25
votes

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)
5
Check this thread. They recommend you update your play services to compile 'com.google.android.gms:play-services:9.0.0' and google services to classpath 'com.google.gms:google-services:3.0.0'noogui
go to my answer to fix your problem It's work for me with GCM 2016skygirl

5 Answers

30
votes

So the issue is that you have dependencies that inlcude old versions of the support library. Check this thread out:

Android UrbanAirship Crash in takeOff

Doing this might help (from the thread):

configurations.all {
    resolutionStrategy {
        force 'com.android.support:design:23.4.0'
        force 'com.android.support:support-v4:23.4.0'
        force 'com.android.support:appcompat-v7:23.4.0'
    }
}
6
votes

Try this it will solve

configurations.all {
resolutionStrategy {
    force 'com.android.support:design:23.4.0'
    force 'com.android.support:support-v4:23.4.0'
    force 'com.android.support:appcompat-v7:23.4.0'
}

}

if you still have problem then you can solve it as,

Updated the play-services dependencies in build.gradle

    dependencies {
compile 'com.google.android.gms:play-services:9.0.0'}

If any version conflict fix it by adding this in build.gradle (project gradle)

dependencies {
classpath 'com.google.gms:google-services:3.0.0'}
4
votes

update may 27:

we just released an update (version 9.0.1) to fix the incompatibility I mentioned in my first edit.
Please update your dependencies and let us know if this is still an issue.

Thanks!


original answer May 20:

Version 9.0.0 of Google Play services sdk includes an incompatibility with the support library version 24.x (the version released to support Android-N)

Please check that you are using:

dependencies {
    compile 'com.android.support:appcompat-v7:23.3.0'
}

and not com.android.support:appcompat-v7:24.*

1
votes

If you already update Android Support Repository, revert it by replacing m2repository folder at sdk path.

First download Older m2repository :

https://dl-ssl.google.com/android/repository/android_m2repository_r31.zip

SDK Path Find Path of SDK

Replace m2repository folder Replace m2repository folder

1
votes

Just upate your GCM library, it'll fix your Problem.

compile "com.google.android.gms:play-services-gcm:9.2.0"