Failed to create GcmBroadcastReceiver instance.

I tried to create a test application with the GCM service, in accordance with the Google manual https://developer.android.com/google/gcm/client.html#app

But when I get the message - I have this error:

Unable to instantiate receiver com.example.testpushnotification.GcmBroadcastReceiver: java.lang.ClassNotFoundException: could not find class "com.example.testpushnotification.GcmBroadcastReceiver" on path: DexPathList [[zip file "/data/app/com.example.testpush 2.apk "], nativeLibraryDirectories = [/ data / application pb /com.example.testpushnotification-2, / vendor / lib, / system / lib]]

I was looking for all the same questions, but they have no solutions or solutions that did not help or they are out of date.

My manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.testpushnotification" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <permission android:name="com.example.testpushnotification.permission.C2D_MESSAGE" android:protectionLevel="signature"/> <uses-permission android:name="com.example.testpushnotification.permission.C2D_MESSAGE"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> <activity android:name="com.example.testpushnotification.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE"/> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.example.testpushnotification"/> </intent-filter> </receiver> <service android:name=".GcmIntentService"/> </application> 

And the source code for the GcmBroadcastReceiver in the com.example.testpushnotification package:

 public class GcmBroadcastReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); } 

And why does the Dex path contain a different package than mine?

Please, how to fix it?

FIXED Modified <receiver android:name=".GcmBroadcastReceiver" .. </receiver>

before <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" .. </receiver> (case sensitivity)

+7
android google-cloud-messaging
source share
4 answers

Try the following:

Go to the "Project / Properties / Java Build Path / Order and Export" section. Make sure you check them before using Android dependencies and the support library if you use it. Check all checkboxes. Click Apply and Clean Up Project.

Add the following:

  <receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.test.android" /> </intent-filter> </receiver> 

It should be: com.google.android.gcm.GCMBroadcastReceiver , not .GCMBroadcastReceiver

It worked for me. Hope this helps.

+7
source share

I followed the developer.android tutorial :/google/gcm/client.html

My problem was that I had the “Android Dependencies” marked under Properties-> Java Build Path-> Order and Export .

List of relevant libraries:

  • Android 4.4.2
  • Android private libraries
  • Android Support-v4

Hope this helps someone out there!

This code was right

 <receiver android:name=".GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.infostretch.iSOSAndroid" /> </intent-filter> </receiver> 
+2
source share

I faced the same problem. But decided, let me share my decision steps.

  • I created a new package and then moved BroadcastReceiver to this package.
  • Add TAG receiver declaration After the activity tag, which provides the registered GCM ID to the correct package name.

my main problem was the GcmBroadcastReceiver class, which extends WakefulBroadcastReceiver and requires the v4 library. For some reason, I have added several libraries, one of which contains v4, I just delete this v4 from this library. Add v7 as a library to my application, then clean and run ... then it works. Sorry for my poor English, I just shared my experience to help.

+1
source share

Mi Fix had to use the manifest editor wizard to change the name of the service and the recipient. Result:

 <application android:allowBackup="true" android:icon="@drawable/journey_icon" android:logo="@drawable/journey_icon" android:permission="android.permission.INTERNET" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <receiver android:name=".GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.example.JourneyApp" /> </intent-filter> </receiver> <service android:name=".GCMIntentService" /> 

Changed to

 <application android:allowBackup="true" android:icon="@drawable/journey_icon" android:logo="@drawable/journey_icon" android:permission="android.permission.INTERNET" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <receiver android:name="journeyAux.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="com.example.JourneyApp" /> </intent-filter> </receiver> <service android:name="journeyAux.GCMIntentService" /> 

0
source share

All Articles