IncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM

Since I updated to Android SDK Tools 25.1.6 and Android Support Repository 32.0.0 (this morning), I got the following error, I didn't change anything in my code and it is still working on my colleague computer (Android SDK Tools 25.1.1 + Android Support Repository 30.0.0).

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 com.xxxxxxx.utils.RegistrationIntentService.onHandleIntent(RegistrationIntentService.java:55)
     at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:145)
     at android.os.HandlerThread.run(HandlerThread.java:61)

Here is a the piece of code that crash:

InstanceID instanceID = InstanceID.getInstance(this); // <-- crash here
String instanceIDToken = instanceID.getToken(getString(R.string.google_app_id),
GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

It is when I try to get a token from Google Cloud Messaging.

I'm importing GCM in Gradle with splited play-services :

 compile 'com.google.android.gms:play-services-analytics:9.0.0' 
 compile 'com.google.android.gms:play-services-maps:9.0.0'
 compile 'com.google.android.gms:play-services-location:9.0.0' 
 compile 'com.google.android.gms:play-services-gcm:9.0.0' 
 compile 'com.google.android.gms:play-services-base:9.0.0'

EDIT disabling GCM fixed the problem, so my guess is I should migrate to Firebase Cloud Message

EDIT2 My device receive Google Play Services 9.0 (yesterday was 8.4.x). Now it doesn't crash anymore, but complain about module descriptor

 Failed to load module descriptor class: Didn't find class "com.google.android.gms.dynamite.descriptors.com.google.firebase.auth.ModuleDescriptor"
 Firebase API initialization failure.

Does anyone has a similar error, and how to fix it ?

FIXED special thanks to @stegranet. ./gradlew -q app:dependencies --configuration compile helps you to identify what dependencies include SDK 24.x

Main issue is some library import the latest support library using + sign instead of a version. This cause the issue, by including the latest available version.

So avoid + sign in dependencies ;)


Solution 1:

I used the gradle dependency tree to solve this error for me.

Just run gradle -q app:dependencies --configuration compile and check the output for entries like this:

+--- com.mcxiaoke.viewpagerindicator:library:2.4.1
|    \--- com.android.support:support-v4:+ -> 24.0.0-beta1 (*)

As Diego Giorgini said this version is too high (>=24). So update the dependencies in build.gradle like

compile('com.mcxiaoke.viewpagerindicator:library:2.4.1') {
    exclude module: 'support-v4';
}
compile 'com.android.support:support-v4:23.4.0'

Solution 2:

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:

The issue you are experiencing is due to an incompatibility between
play-services / firebase sdk v9.0.0 and com.android.support:appcompat-v7 >= 24
(the version released with android-N sdk)

You should be able to fix it by targeting an earlier version of the support library. Like:

compile 'com.android.support:appcompat-v7:23.4.0'

Solution 3:

mine worked by with the following:

app level gradle

dependencies {
 compile 'com.android.support:appcompat-v7:23.4.0'
 compile 'com.android.support:design:23.4.0'
 compile 'com.google.android.gms:play-services:9.0.0'
}

root level gradle

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

Solution 4:

I've updated the play-services dependencies in build.gradle

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

To fix the version conflict either by updating the version of the google-services plugin - I had to update the google-services in the build.gradle under the project's root folder

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

You can get the latest update of the google-services here.

Though its not avoiding the exception but its not crashing the application anymore in my side.

Update

I could avoid the crash by updating the Android studio from Beta Channel. Then update your platform/build-tools inside SDK.

enter image description here

Solution 5:

Updating to the latest google play services version fixed the issue for me.

apply plugin: 'com.google.gms.google-services' at the bottom ...

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

https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project