問題描述
自從我更新到 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!