问题描述
自从我更新到 Android SDK Tools 25.1.6 和 Android Support Repository 32.0.0(今天早上)后,我收到了以下错误,我没有更改我的代码中的任何内容,它仍在我同事的计算机上运行(Android SDK 工具 25.1.1 + Android 支持存储库 30.0.0).
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)
这是一段崩溃的代码:
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 获取令牌时.
It is when I try to get a token from Google Cloud Messaging.
我正在使用拆分播放服务在 Gradle 中导入 GCM:
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'
编辑禁用 GCM 解决了这个问题,所以我猜我应该迁移到 Firebase Cloud Message
EDIT disabling GCM fixed the problem, so my guess is I should migrate to Firebase Cloud Message
EDIT2我的设备接收 Google Play Services 9.0(昨天是 8.4.x).现在它不再崩溃了,但是抱怨模块描述符
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 ?
已修复特别感谢@stegranet../gradlew -q app:dependencies --configuration compile
帮助您识别 SDK 24.x 包含哪些依赖项
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 ;)
推荐答案
我使用gradle依赖树为我解决了这个错误.
I used the gradle dependency tree to solve this error for me.
只需运行 gradle -q app:dependencies --configuration compile
并检查输出是否有这样的条目:
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 (*)
正如 Diego Giorgini 所说,这个版本太高了 (>=24).所以像
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'
这篇关于更新到 Android Build Tools 25.1.6 GCM/FCM 后出现 IncompatibleClassChangeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!