'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:[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:[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 betweenplay-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:[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:[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.
Solution 5:[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
Solution 6:[6]
Happened to me because of facebook updating it sdk and I had
compile 'com.facebook.android:facebook-android-sdk:4.+'
replacing it to
compile 'com.facebook.android:facebook-android-sdk:4.15.0'
solved my issuee.
Ref: https://developers.facebook.com/docs/android/change-log-4.x
Solution 7:[7]
By including all the play services' packages
dependencies {
compile 'com.google.android.gms:play-services:9.0.0'
}
you supress the error, but the end result is, that the GCM token retrieval is not working nor we can get an instance of the GCM. So this is not a solution in my books. If anyone has any idea what is going on please enlighten us.
EDIT:
I replaced GCM with firebase, updated android studio from 2.1 to 2.2 to fix the instant run issue with firebase analytics, updated build tools to 24-rc4 and platform tools to 24-rc3, and kept my support libs' version to 23.4.0. Everything seems to be working good now.
Solution 8:[8]
I had the same problem and reverting from Android Support Repository 32.0.0 to Android Support Repository 31.0.0 solved it.
Solution 9:[9]
For Android push notification with GCM 2016 :
1) in Android SDK-> SDK Tools check Google Play services
2) in gradle add in dependencies just one line :
compile 'com.google.android.gms:play-services-gcm:9.4.0'
(there is no specific classpath and it works for me)
3) you must create 3 class (GCMPushReceiverService, GCMRegistrationIntentService, GCMTokenRefreshListenerService)
4.1) code for GCMTokenRefreshListenerService :
package com.myapp.android;
/**
* Created by skygirl on 02/08/2016.
*/
import android.content.Intent;
import com.google.android.gms.iid.InstanceIDListenerService;
public class GCMTokenRefreshListenerService extends InstanceIDListenerService {
//If the token is changed registering the device again
@Override
public void onTokenRefresh() {
Intent intent = new Intent(this, GCMRegistrationIntentService.class);
startService(intent);
}
}
4.2) Code for GCMRegistrationIntentService (change authorizedEntity with your project number) :
package com.myapp.android;
/**
* Created by Skygirl on 02/08/2016.
*/
import android.app.IntentService;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.android.gms.iid.InstanceID;
public class GCMRegistrationIntentService extends IntentService {
//Constants for success and errors
public static final String REGISTRATION_SUCCESS = "RegistrationSuccess";
public static final String REGISTRATION_ERROR = "RegistrationError";
//Class constructor
public GCMRegistrationIntentService() {
super("");
}
@Override
protected void onHandleIntent(Intent intent) {
//Registering gcm to the device
registerGCM();
}
private void registerGCM() {
//Registration complete intent initially null
Intent registrationComplete = null;
//Register token is also null
//we will get the token on successfull registration
String token = null;
try {
//Creating an instanceid
InstanceID instanceID = InstanceID.getInstance(this);
String authorizedEntity = "XXXXXXXXXX"; // your project number
//Getting the token from the instance id
token = instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
//Displaying the token in the log so that we can copy it to send push notification
//You can also extend the app by storing the token in to your server
Log.w("GCMRegIntentService", "token:" + token);
//on registration complete creating intent with success
registrationComplete = new Intent(REGISTRATION_SUCCESS);
//Putting the token to the intent
registrationComplete.putExtra("token", token);
} catch (Exception e) {
//If any error occurred
Log.w("GCMRegIntentService", "Registration error");
registrationComplete = new Intent(REGISTRATION_ERROR);
}
//Sending the broadcast that registration is completed
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
}
4.3) Code for GCMPushReceiverService :
package com.myapp.android;
/**
* Created by Skygirl on 02/08/2016.
*/
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import com.google.android.gms.gcm.GcmListenerService;
//Class is extending GcmListenerService
public class GCMPushReceiverService extends GcmListenerService {
//This method will be called on every new message received
@Override
public void onMessageReceived(String from, Bundle data) {
//Getting the message from the bundle
String message = data.getString("message");
//Displaying a notiffication with the message
sendNotification(message);
}
//This method is generating a notification and displaying the notification
private void sendNotification(String message) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
int requestCode = 0;
PendingIntent pendingIntent = PendingIntent.getActivity(this, requestCode, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.your_logo)
.setContentTitle("Your Amazing Title")
.setContentText(message)
.setPriority(Notification.PRIORITY_MAX)
.setContentIntent(pendingIntent);
noBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, noBuilder.build()); //0 = ID of notification
}
}
5) Don't forget to change package name
6) In your mainActivity paste this code :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Setup view
setContentView(R.layout.main);
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
//When the broadcast received
//We are sending the broadcast from GCMRegistrationIntentService
public void onReceive(Context context, Intent intent) {
//If the broadcast has received with success
//that means device is registered successfully
if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_SUCCESS)){
//Getting the registration token from the intent
String token = intent.getStringExtra("token");
//Displaying the token as toast
Toast.makeText(getApplicationContext(), "Registration token:" + token, Toast.LENGTH_LONG).show();
//if the intent is not with success then displaying error messages
} else if(intent.getAction().equals(GCMRegistrationIntentService.REGISTRATION_ERROR)){
Toast.makeText(getApplicationContext(), "GCM registration error!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Error occurred", Toast.LENGTH_LONG).show();
}
}
};
//Checking play service is available or not
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
//if play service is not available
if(ConnectionResult.SUCCESS != resultCode) {
//If play service is supported but not installed
if(GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
//Displaying message that play service is not installed
Toast.makeText(getApplicationContext(), "Google Play Service is not install/enabled in this device!", Toast.LENGTH_LONG).show();
GooglePlayServicesUtil.showErrorNotification(resultCode, getApplicationContext());
//If play service is not supported
//Displaying an error message
} else {
Toast.makeText(getApplicationContext(), "This device does not support for Google Play Service!", Toast.LENGTH_LONG).show();
}
//If play service is available
} else {
//Starting intent to register device
Intent itent = new Intent(this, GCMRegistrationIntentService.class);
startService(itent);
}
}
//Unregistering receiver on activity paused
@Override
public void onPause() {
super.onPause();
Log.w("MainActivity", "onPause");
LocalBroadcastManager.getInstance(this).unregisterReceiver(mRegistrationBroadcastReceiver);
}
@Override
public void onResume() {
super.onResume();
Log.w("MainActivity", "onResume");
LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
new IntentFilter(GCMRegistrationIntentService.REGISTRATION_SUCCESS));
LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
new IntentFilter(GCMRegistrationIntentService.REGISTRATION_ERROR));
}
7) In your AndroidManifest.xml add following lines :
<uses-permission android:name="android.permission.INTERNET" />
8) in your console logcat copy your token and paste on this site add your project number, your token and a message. It's work fine for me :)
Solution 10:[10]
After a full day on this, I can confirm 100% that the Optimizely library is also clashing in some way and causing this error. To be specific, I am using Optimizely via Fabric. It is impossible to get Firebase to initialize whilst using Optimizely in this way (maybe in all ways?).
I have posted on their github about it and will contact them directly ...
https://github.com/optimizely/Optimizely-Android-SDK/issues/11
Solution 11:[11]
I had the same problem. I updated SDK tools to 25.1.7 rc1, then the problem was gone.
Solution 12:[12]
updated SDK tools to 25.1.7 and fixed this issue.
Solution 13:[13]
Well, I am just beginner of using Android.
I wanted to test creating users in Firebase
following instructions which is provided in the Firebase website.
I added those lines in indicated places.
classpath 'com.google.gms:google-services:3.0.0'
compile 'com.google.firebase:firebase-auth:9.2.0'
apply plugin: 'com.google.gms.google-services'
But createUserWithEmailAndPassword Method kept showing failure in creating users. That's why I visited this question to figure out my problem. I read all and applied each advice. but IT kept showing failure. But When I upgrade Android Studio from 2.1.1 to 2.1.2
, I could create users successfully.
But when I checked logcat
, it first showed "Firebase API initialization failure"
and then showed "FirebaseApp initialization successful".
07-09 18:53:37.012 13352-13352/jayground.firebasetest A/FirebaseApp: Firebase API initialization failure. How can I solve
this? java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) 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.zzeh(Unknown Source) at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source) at android.content.ContentProvider.attachInfo(ContentProvider.java:1591) at android.content.ContentProvider.attachInfo(ContentProvider.java:1562) at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) at android.app.ActivityThread.installProvider(ActivityThread.java:5118) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4713) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4596) at android.app.ActivityThread.access$1600(ActivityThread.java:169) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5487) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NoSuchMethodError: com.google.android.gms.common.internal.zzaa.zzz at com.google.android.gms.measurement.internal.zzx.zzbd(Unknown Source) at com.google.android.gms.measurement.AppMeasurement.getInstance(Unknown Source) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) 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.zzeh(Unknown Source) at com.google.firebase.provider.FirebaseInitProvider.onCreate(Unknown Source) at android.content.ContentProvider.attachInfo(ContentProvider.java:1591) at android.content.ContentProvider.attachInfo(ContentProvider.java:1562) at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source) at android.app.ActivityThread.installProvider(ActivityThread.java:5118) at android.app.ActivityThread.installContentProviders(ActivityThread.java:4713) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4596) at android.app.ActivityThread.access$1600(ActivityThread.java:169) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1340) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5487) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) at dalvik.system.NativeStart.main(Native Method) 07-09 18:53:37.022 13352-13352/jayground.firebasetest I/FirebaseInitProvider: FirebaseApp initialization successful
Solution 14:[14]
I have faced this problem, and i change my app gradle version from 1.5.0 to 2.0.0.
change classpath
com.android.tools.build:gradle:1.5.0
to
classpath 'com.android.tools.build:gradle:2.0.0
Solution 15:[15]
Solution 1:
dependencies {
compile `com.android.support:appcompat-v7:23.4.0`
compile `com.android.support:support-v4:23.4.0`
compile `com.android.support:design:23.4.0`
compile `com.google.android.gms:play-services:9.0.0`
}
Solution 2: detect incompatible on folder .idie/libraries/ .some time you declare play-services-ads:8.4.0 concurrent with play-services-gcm:9.0.0 .you must override on build.grade incompatible libraries you detected
Solution 16:[16]
We had a similar issue in release build with message
"The method (com.xx.classname.method) was expected to be of type virtual but instead was found to be of type static (declaration of companion object appears in submodule.apk)
The issue was resolved by adding the proguard rules for okhttp3
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow