- 安卓工作室版本:3.4.1
- Firebase 组件: Firebase 消息传递:
- 组件版本:17.3.2
嗨,伙计们,我在迁移使用火力消息传递到 androidx 的应用程序时遇到问题。我按照说明 https://developer.android.com/jetpack/androidx/migrate
不幸的是,看起来火力基地组件尚未迁移
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/util/ArrayMap;
at com.google.firebase.FirebaseApp.<clinit>(com.google.firebase:firebase-common@@17.1.0:101)
at com.google.firebase.FirebaseApp.initializeApp(com.google.firebase:firebase-common@@17.1.0:244)
at com.google.firebase.provider.FirebaseInitProvider.onCreate(com.google.firebase:firebase-common@@17.1.0:53)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1927)
at android.content.ContentProvider.attachInfo(ContentProvider.java:1902)
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(com.google.firebase:firebase-common@@17.1.0:47)
at android.app.ActivityThread.installProvider(ActivityThread.java:6578)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6133)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6043)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.util.ArrayMap" on path: DexPathList
有什么解决方法吗?我认为以某种方式神奇地通过添加来解决:
android.useAndroidX=true
android.enableJetifier=true
无论如何。。我不知道(因为FirebaseApp仍然持有v4支持库的旧依赖项(。我错过了什么吗?感谢您的任何帮助。
build.gradle
compileSdkVersion 28
buildToolsVersion "27.0.3"
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode project.sdkVersionCode
versionName project.sdkVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
configurations.all { exclude group: 'com.android.support', module: 'support-v4'}
configurations.all { exclude group: 'com.android.support', module: 'support-compat'}
configurations.all { exclude group: 'com.android.support', module: 'support-annotations'}
dependencies {
implementation 'androidx.core:core:1.0.2'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.okhttp3:okhttp:3.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.0.0'
implementation 'com.squareup.retrofit2:converter-gson:2.0.0'
implementation 'io.reactivex:rxandroid:1.2.0'
implementation 'com.google.firebase:firebase-messaging:17.3.2'
implementation 'com.google.firebase:firebase-common:17.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
implementation 'com.madgag.spongycastle:core:1.58.0.0'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
transitive = true
}
testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.15.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
我发现了一个问题,解决方案是将构建 gradle 版本更新到至少 3.2.0。这也是通过 android 工作室自动迁移所说的">将构建 gradle 插件升级到至少 3.2.0">
classpath 'com.android.tools.build:gradle:3.2.0'
然而,从实施的角度来看,这很奇怪...人们很容易感到困惑...
如果插件版本<3.2.0,则会下载来自 v4 支持的旧 ArrayMap 并将其放置在 FirebaseApp 类中的缓存中。
如果> 3.2.0,则会从 androidx 软件包中获取 ArrayMap。
我认为您缺少现在托管该文件的AndroidX集合库:
https://developer.android.com/reference/androidx/collection/ArrayMap.html
implementation 'androidx.collection:collection:1.0.0'