大家好, 我将使用Firebase消息传递到androidx的应用程序迁移时遇到问题。 我按照说明https://developer.android.com/jetpack/androidx/migrate
不幸的是,似乎Firebase组件尚未迁移
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'
}
答案 0 :(得分:0)
我认为您缺少现在托管该文件的AndroidX Collections库:
https://developer.android.com/reference/androidx/collection/ArrayMap.html
implementation 'androidx.collection:collection:1.0.0'
答案 1 :(得分:0)
我发现了一个问题,解决方案是将build gradle版本更新到至少3.2.0。这也是通过android studio自动迁移时所说的“ 将build gradle插件升级到至少3.2.0 ”
classpath 'com.android.tools.build:gradle:3.2.0'
但是,从实现的角度来看,这是很奇怪的……而且人们很容易混淆...
如果插件版本<3.2.0,则将下载v4支持的旧ArrayMap并将其放在FirebaseApp类的缓存中。
如果> 3.2.0,则使用androidx包中的ArrayMap。