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.