My Android application started crashing today when generating a token for Google Cloud Messaging (GCM). This happens on multiple devices and version of Android. I think it may have to do with the new Firebase features announced by Google yesterday at Google IO.
I wasn't working around the code related to GCM when this started happening so it was unexpected. If I uninstall Google Play Services updates from Android system settings, the app no longer crashes. As soon as I re-install the latest, the app starts crashing again every time.
FATAL EXCEPTION: IntentService[MyGCMRegistrationIntentService]
Process: <my process>, PID: 26036
java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)
at com.google.android.gms.iid.zzd.zzeb(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 <package>.MyGCMRegistrationIntentService.onHandleIntent(MyGCMRegistrationIntentService.java:<line number>);
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.os.HandlerThread.run(HandlerThread.java:61)
Here is my registration service:
public class MyGCMRegistrationIntentService extends IntentService
{
public static final String KEY_GCM_TOKEN = "gcm_token";
public static final String KEY_GCM_INSTANCE_ID = "gcm_instance_id";
private static final String NAME = MyGCMRegistrationIntentService.class.getSimpleName();
public MyGCMRegistrationIntentService()
{
super(NAME);
}
@Override
protected void onHandleIntent(final Intent intent)
{
try
{
final InstanceID instanceId = InstanceID.getInstance(this);
final String token = instanceId.getToken(getGCMSenderID(), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
final String instanceIdId = instanceId.getId();
sendTokenToMyServer(token, instanceIdId);
}
catch (final IOException e)
{
Timber.e(e, "Error getting GCM token.");
}
}
}
Top-level Gradle build file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'de.felixschulze.gradle:gradle-hockeyapp-plugin:3.3'
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:2.1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
}
App-level Gradle build dependencies dealing with Google:
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:support-annotations:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:support-v13:23.3.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
...(and then the rest of my dependecies)
}
Library dependencies dealing with Google (I know this is all messy and some things are redundant, sorry):
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:cardview-v7:23.3.0'
compile 'com.android.support:recyclerview-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:support-v13:23.3.0'
compile 'com.google.android.gms:play-services-location:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
...(and then the rest of my dependecies)
}
I thought maybe upgrading the versions would help. Here is what I upgraded:
com.google.gms:google-services:2.1.0 -> com.google.gms:google-services:3.0.0
com.google.android.gms:play-services-XXX:8.4.0' -> com.google.android.gms:play-services-XXX:9.0.0
The application still crashes, but in a different way. First it logs the following, but does not crash.
Firebase API initialization failure.
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1696)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1671)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:4999)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4594)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4534)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)
at com.google.firebase.iid.zzg.zzeC(Unknown Source)
at com.google.firebase.iid.zzg.<init>(Unknown Source)
at com.google.firebase.iid.zzg.<init>(Unknown Source)
at com.google.firebase.iid.zzd.zzb(Unknown Source)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.google.firebase.FirebaseApp.zza(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
at com.google.firebase.FirebaseApp.zzbu(Unknown Source)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1696)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1671)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:4999)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4594)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4534)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
After I move around in the app which triggers the GCM registration, I get the same stack as before along with this line before crashing:
E/FA: Task exception on worker thread: java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar): com.google.android.gms.measurement.internal.zzt.zzEd(Unknown Source)