更新到Android构build工具后的IncompatibleClassChangeError 25.1.6 GCM / FCM

由于我更新了Android SDK Tools 25.1.6和Android Support Repository 32.0.0(今天上午),我得到了以下错误,我没有改变我的代码中的任何东西,它仍然在我的同事计算机上工作(Android SDK工具25.1.1 + Android支持库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) 

这是一个崩溃的代码片段:

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

当我尝试从Google Cloud Messaging获取令牌时。

我正在用分裂的播放服务在Gradle中导入GCM:

  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' 

编辑禁用GCM固定的问题,所以我的猜测是我应该迁移到Firebase云消息

EDIT2我的设备收到Google Play服务9.0(昨天是8.4.x)。 现在它不再崩溃,但抱怨模块描述符

  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. 

有没有人有类似的错误,以及如何解决?

固定特别感谢@stegranet。 ./gradlew -q app:dependencies --configuration compile帮助你确定哪些依赖包括SDK 24.x

主要问题是一些库导入最新的支持库使用+符号而不是一个版本。 这会导致问题,包括最新的可用版本。

所以避免+login依赖项;)

我用gradle依赖树来解决这个错误。

只需运行gradle -q app:dependencies --configuration compile并检查输出,如下所示:

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

正如Diego Giorgini所说,这个版本太高(> = 24)。 所以更新build.gradle的依赖关系

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

更新5月27日:

我们刚刚发布了一个更新( version 9.0.1 )来修复我在第一次编辑中提到的不兼容问题。
请更新您的依赖关系,并让我们知道这是否仍然是一个问题。

谢谢!


原来的答案5月20日:

您遇到的问题是由于之间的不兼容
play-services / firebase sdk v9.0.0com.android.support:appcompat-v7 >= 24
(使用android-N sdk发布的版本)

您应该能够通过定位早期版本的支持库来修复它。 喜欢:

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

我的工作如下:

应用程序级别的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' } 

根级gradle

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

我更新了build.gradle的play-services依赖关系

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

要通过更新google-services插件的版本来修复版本冲突 – 我必须更新项目根文件夹下的build.gradle的google-services

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

您可以在这里获得最新的google服务更新。

虽然它不避免例外,但它不会在我的身边崩溃的应用程序。

更新

我可以通过从Beta频道更新Android工作室来避免崩溃。 然后在SDK中更新你的platform/build-tools

在这里输入图像描述

更新到最新的谷歌播放服务版本解决了我的问题。

应用插件:位于底部的“com.google.gms.google-services”…

 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

发生在我身上,因为facebook更新了它,我有

 compile 'com.facebook.android:facebook-android-sdk:4.+' 

取代它

 compile 'com.facebook.android:facebook-android-sdk:4.15.0' 

解决了我的问题

参考: https : //developers.facebook.com/docs/android/change-log-4.x

通过包括所有的播放服务的软件包

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

你压制错误,但最终的结果是,GCM令牌检索不起作用,我们也可以得到一个GCM的实例。 所以这不是我书中的解决scheme。 如果有人有什么想法是怎么回事,请启发我们。

编辑:

我用firebasereplace了GCM,更新了android studio 2.1到2.2,解决了firebase分析的即时运行问题,更新了24-rc4的构build工具和24-rc3的平台工具,并将我的支持库版本保持为23.4.0。 现在一切似乎都很好。

我有同样的问题,并从Android支持库32.0.0到Android支持库31.0.0解决了它。

对于GCM 2016的Android推送通知:

1)在Android SDK-> SDK工具中检查Google Play服务

2)在gradle中添加依赖只有一行:

 compile 'com.google.android.gms:play-services-gcm:9.4.0' 

(没有具体的类path,它适用于我)

3)你必须创build3类(GCMPushReceiverService,GCMRegistrationIntentService,GCMTokenRefreshListenerService)

4.1)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)GCMRegistrationIntentService的代码(用您的项目编号更改authorizedEntity):

 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)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)不要忘记更改包名称

6)在你的mainActivity粘贴这段代码:

 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)在你的AndroidManifest.xml中添加以下几行:

 <uses-permission android:name="android.permission.INTERNET" /> 

8)在你的控制台logcat中复制你的令牌并粘贴到这个网站上添加你的项目号,你的令牌和消息。 这对我来说很好:)

在这一整天后,我可以确认100%Optimizely库也以某种方式冲突,并导致此错误。 具体来说,我通过Fabric使用Optimizely。 以这种方式使用Optimizely是不可能获得Firebase初始化的(也许在所有方面?)。

我已经发布在他们的github上,并会直接与他们联系…

https://github.com/optimizely/Optimizely-Android-SDK/issues/11

我有同样的问题。 我更新了SDK工具到25.1.7 rc1,然后问题就没有了。

更新了SDK工具到25.1.7并解决了这个问题。

那么,我只是使用Android的初学者。 我想按照Firebase网站中提供的说明testing在Firebase创build用户。

我在指定的地方添加了这些行。

classpath'com.google.gms:google-services:3.0.0'

编译“com.google.firebase:firebase-auth:9.2.0”

应用插件:“com.google.gms.google-services”

但createUserWithEmailAndPassword方法在创build用户时一直显示失败。 这就是为什么我访问了这个问题来找出我的问题。 我读了所有,并应用每个build议。 但IT一直在显示失败。 但是当我将Android Studio from 2.1.1 to 2.1.2升级Android Studio from 2.1.1 to 2.1.2 ,我可以成功创build用户。

但是当我检查logcat ,它首先显示"Firebase API initialization failure" ,然后显示“FirebaseApp初始化成功”。

 07-09 18:53:37.012 13352-13352/jayground.firebasetest A/FirebaseApp: Firebase API initialization failure. How can I solve 

这个? java.lang.reflect.Method.invokeNative(Native Method)java.lang.reflect.Method.invoke(Method.java:515)at com.google.firebase.FirebaseApp.zza(Unknown源)com.google.firebase.FirebaseApp.initializeApp(未知源),com.google.firebase.FirebaseApp.initializeApp(未知源),com.google.firebase.FirebaseApp.zzeh(未知源),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(未知源)在android.app.ActivityThread.handleBindApplication(ActivityThread.java:4596)android.app.ActivityThread.installProvider(ActivityThread.java:5118)在android.app.ActivityThread.installContentProviders(ActivityThread.java:4713) )在android.app.ActivityThread.access $ 1600(ActivityThread.java:169)在和 在android.app.android.os.Handler.dispatchMessage(Handler.java:102)android.os.Looper.loop(Looper.java:146)上的roid.app.ActivityThread $ H.handleMessage(ActivityThread.java:1340) .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)引起:java.lang .NoSuchMethodError:com.google.android.gms.monternal.zzx.zzbd(未知来源)com.google.android.gms.measurement.AppMeasurement上的com.google.android.gms.common.internal.zzaa.zzz .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 )在com.google.firebase.FirebaseApp.initializeApp(未知来源) com.google.firebase.FirebaseApp.initializeApp(未知源代码),位于com.google.firebase.FirebaseApp.zzeh(未知源代码),位于com.google.firebase.provider.FirebaseInitProvider.onCreate(未知源代码)上,位于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 )在android.app.ActivityThread $ h.handleMessage(ActivityThread.java:1340)在android.os.Handler.dispatchMessage(Handler.java:102)在android.os.Looper.loop(Looper.java:146)在android .app.ActivityThread.main(ActivityThread.java:5487)at java.lang.reflect.Method.invokeNative(Nati (方法)在java.lang.reflect.Method.invoke(Method.java:515)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初始化成功

我遇到了这个问题,我将应用程序gradle版本从1.5.0更改为2.0.0。

改变classpath

com.android.tools.build:gradle:1.5.0

classpath 'com.android.tools.build:gradle:2.0.0

解决scheme1:

 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` } 

解决scheme2:检测文件夹.idie / libraries /中的不兼容。您声明play-services-ads:8.4.0与play-services-gcm:9.0.0并发时,您必须覆盖您检测到的build.grade不兼容库