1

This seems to be the complete error:

11-07 16:07:44.646 27955-27995/com.chatapp.gcm.chatapp E/UncaughtException: java.lang.IncompatibleClassChangeError: android.support.v4.content.ContextCompat
at com.google.android.gms.iid.zzd.zzeC(Unknown Source)
at com.google.android.gms.iid.zzd.<init>(Unknown Source)
at com.google.android.gms.iid.zzd.<init>(Unknown Source)
at com.google.android.gms.iid.InstanceID.zza(Unknown Source)
at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
at com.chatapp.gcm.chatapp.gcm.GcmIntentService.registerGCM(GcmIntentService.java:63)
at com.chatapp.gcm.chatapp.gcm.GcmIntentService.onHandleIntent(GcmIntentService.java:50)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.os.HandlerThread.run(HandlerThread.java:61)

Here is the line 63 from GcmIntentService.java:

InstanceID instanceID = InstanceID.getInstance(this);

Here is the code around that line:

private void registerGCM() {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
String token = null;

try {
    InstanceID instanceID = InstanceID.getInstance(this);
    token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

    Log.e(TAG, "GCM Registration Token: " + token);

    // sending the registration id to our server
    sendRegistrationToServer(token);

    sharedPreferences.edit().putBoolean(Config.SENT_TOKEN_TO_SERVER, true).apply();
} catch (Exception e) {
    Log.e(TAG, "Failed to complete token refresh", e);

    sharedPreferences.edit().putBoolean(Config.SENT_TOKEN_TO_SERVER, false).apply();
}

I have been trying to solve this issue for 5 hours now. The app has stopped crashing after I updated Google play services plugin as mentioned on some other answers but it is still not generating the token. Any help would be appreciated.

Vineet Sharma
  • 221
  • 2
  • 11

1 Answers1

0

AFAIK, IncompatibleClassChangeError error is usually due to mismatch between the SDK that is being used and the version of Google Play services that is available on the device or could also be due to dependency version conflicts.

With these, you may want check declared dependencies in your build.gradle when you set up Google Play services. Also, using ResolutionStrategy could help resolve dependency version conflicts.

For additional insights, check these links:

Teyam
  • 7,686
  • 3
  • 15
  • 22