How to fix issues with NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string on Android
How to fix issues with NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string on Android
最近,我遇到了一个问题,我一周都无法解决,阅读了不同的资源和建议。但是,没有任何帮助。
所以,问题出在升级后出现的NoClassDefFoundError:
- Gradle 从 5.x 到 6.x
的包装器
- Gradle 构建工具
- Firebase 依赖项(它们实际上带来了这些 类 我有问题)
我已经尝试解决的问题:
- 试图降级 Firbase 库(我只有核心、广告和分析)
- 试图禁用传递basemenet依赖
- 尝试应用 BOM 来同步依赖项
- 尝试 upgrade/downgrade android 构建插件
- 试图找出现有 green-dao 版本的问题,但看起来不错
这是我的 build.gradle 文件中的依赖项:
dependencies {
implementation "com.jakewharton.timber:timber:$timberVersion"
//Reactive
implementation group: 'io.reactivex.rxjava2', name: 'rxjava', version: rxJavaVersion
implementation group: 'io.reactivex.rxjava2', name: 'rxandroid', version: androidRxJavaVersion
// Firebase dependencies
implementation platform("com.google.firebase:firebase-bom:$androidFirebaseBomVersion")
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-ads'
implementation 'com.google.firebase:firebase-crashlytics'
// Android lifecycle
implementation "androidx.lifecycle:lifecycle-runtime:$androidLifeCycleVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$androidLifeCycleVersion"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$androidLifeCycleVersion"
// Android support
//TODO once can be replaced with com.google.android.material
implementation "com.google.android.material:material:$androidMaterialVersion"
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.appcompat:appcompat:$androidAppCompatVersion"
implementation "androidx.constraintlayout:constraintlayout:$androidSupportConstraintLayoutVersion"
implementation 'androidx.multidex:multidex:2.0.1'
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
// Dependency injection (Dagger)
implementation "com.google.dagger:dagger:$daggerVersion"
implementation "com.google.dagger:dagger-android:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
// Database
implementation "org.sqldroid:sqldroid:$sqlDroidVersion"
implementation "org.flywaydb:flyway-core:$flywayVersion"
// UI
implementation "com.afollestad.material-dialogs:core:$materialDialogsVersion"
implementation "com.github.hotchemi:android-rate:$androidRateVersion"
implementation 'androidx.cardview:cardview:1.0.0'
implementation "com.nex3z:flow-layout:$flowLayoutVersion"
// Utils
implementation "com.annimon:stream:$streamVersion"
implementation "com.google.code.findbugs:jsr305:$findBugsVersion"
implementation "net.objecthunter:exp4j:$exp4jVersion"
// Checkout
implementation "org.solovyev.android:checkout:$checkoutVersion"
/**
* Test dependencies
*/
// Unit tests
testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: hamcrestAllVersion
testImplementation("junit:junit:$junitVersion") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
testImplementation('androidx.arch.core:core-testing:2.1.0') {
exclude group: "com.android.support", module: "support-annotations"
}
testImplementation 'net.sf.kxml:kxml2:2.3.0'
// Integration tests
androidTestImplementation "junit:junit:$junitVersion"
// Espresso dependencies
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
androidTestImplementation "com.google.code.findbugs:jsr305:$jsr305Version"
androidTestImplementation "androidx.test:runner:$testRunnerVersion"
androidTestImplementation "androidx.test:rules:$testRunnerVersion"
androidTestUtil "androidx.test:orchestrator:$testOrchestratorVersion"
androidTestImplementation "commons-io:commons-io:$commonsIOVersion"
androidTestImplementation group: 'com.google.guava', name: 'guava', version: guavaVersion
// Spoon
androidTestImplementation "com.squareup.spoon:spoon-client:$spoonClientVersion"
}
这是堆栈跟踪:
09-15 11:07:13.467 1129 1129 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string;
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.google.android.gms.common.internal.StringResourceValueReader.<init>(Unknown Source)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.google.firebase.FirebaseOptions.fromResource(FirebaseOptions.java:156)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:244)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.content.ContentProvider.attachInfo(ContentProvider.java:1759)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.content.ContentProvider.attachInfo(ContentProvider.java:1734)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread.installProvider(ActivityThread.java:6420)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread.installContentProviders(ActivityThread.java:6012)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5951)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread.-wrap3(ActivityThread.java)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1710)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.os.Looper.loop(Looper.java:154)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6776)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.R$string" on path: DexPathList[[zip file "/data/app/com.myestimates.buildercalcfree-2/base.apk"],nativeLibraryDirectories=[/data/app/com.myestimates.buildercalcfree-2/lib/arm, /system/lib, /vendor/lib]]
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: ... 18 more
也许这是一个常见的问题,但我不知道如何处理它。
谢谢
所以,经过几天的挖掘,我找到了解决方案。所以,为了让它发挥作用,我必须:
- 将AndroidGradle插件降级到3.5.3版本
- 将Gordon插件降级到1.0.6版本
- 已将 fabric-crashlytic 迁移到 firebase-crashlytic。加上最后一个插件,否则会出错
所有其他更新都可以设置,但这3项必须坚持提到的版本。
最近,我遇到了一个问题,我一周都无法解决,阅读了不同的资源和建议。但是,没有任何帮助。
所以,问题出在升级后出现的NoClassDefFoundError:
- Gradle 从 5.x 到 6.x 的包装器
- Gradle 构建工具
- Firebase 依赖项(它们实际上带来了这些 类 我有问题)
我已经尝试解决的问题:
- 试图降级 Firbase 库(我只有核心、广告和分析)
- 试图禁用传递basemenet依赖
- 尝试应用 BOM 来同步依赖项
- 尝试 upgrade/downgrade android 构建插件
- 试图找出现有 green-dao 版本的问题,但看起来不错
这是我的 build.gradle 文件中的依赖项:
dependencies {
implementation "com.jakewharton.timber:timber:$timberVersion"
//Reactive
implementation group: 'io.reactivex.rxjava2', name: 'rxjava', version: rxJavaVersion
implementation group: 'io.reactivex.rxjava2', name: 'rxandroid', version: androidRxJavaVersion
// Firebase dependencies
implementation platform("com.google.firebase:firebase-bom:$androidFirebaseBomVersion")
implementation 'com.google.firebase:firebase-core'
implementation 'com.google.firebase:firebase-ads'
implementation 'com.google.firebase:firebase-crashlytics'
// Android lifecycle
implementation "androidx.lifecycle:lifecycle-runtime:$androidLifeCycleVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$androidLifeCycleVersion"
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$androidLifeCycleVersion"
// Android support
//TODO once can be replaced with com.google.android.material
implementation "com.google.android.material:material:$androidMaterialVersion"
implementation 'androidx.browser:browser:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.appcompat:appcompat:$androidAppCompatVersion"
implementation "androidx.constraintlayout:constraintlayout:$androidSupportConstraintLayoutVersion"
implementation 'androidx.multidex:multidex:2.0.1'
implementation "com.squareup.okhttp3:okhttp:$okHttpVersion"
// Dependency injection (Dagger)
implementation "com.google.dagger:dagger:$daggerVersion"
implementation "com.google.dagger:dagger-android:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-android-processor:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
// Database
implementation "org.sqldroid:sqldroid:$sqlDroidVersion"
implementation "org.flywaydb:flyway-core:$flywayVersion"
// UI
implementation "com.afollestad.material-dialogs:core:$materialDialogsVersion"
implementation "com.github.hotchemi:android-rate:$androidRateVersion"
implementation 'androidx.cardview:cardview:1.0.0'
implementation "com.nex3z:flow-layout:$flowLayoutVersion"
// Utils
implementation "com.annimon:stream:$streamVersion"
implementation "com.google.code.findbugs:jsr305:$findBugsVersion"
implementation "net.objecthunter:exp4j:$exp4jVersion"
// Checkout
implementation "org.solovyev.android:checkout:$checkoutVersion"
/**
* Test dependencies
*/
// Unit tests
testImplementation group: 'org.hamcrest', name: 'hamcrest-all', version: hamcrestAllVersion
testImplementation("junit:junit:$junitVersion") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
testImplementation('androidx.arch.core:core-testing:2.1.0') {
exclude group: "com.android.support", module: "support-annotations"
}
testImplementation 'net.sf.kxml:kxml2:2.3.0'
// Integration tests
androidTestImplementation "junit:junit:$junitVersion"
// Espresso dependencies
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
androidTestImplementation "com.google.code.findbugs:jsr305:$jsr305Version"
androidTestImplementation "androidx.test:runner:$testRunnerVersion"
androidTestImplementation "androidx.test:rules:$testRunnerVersion"
androidTestUtil "androidx.test:orchestrator:$testOrchestratorVersion"
androidTestImplementation "commons-io:commons-io:$commonsIOVersion"
androidTestImplementation group: 'com.google.guava', name: 'guava', version: guavaVersion
// Spoon
androidTestImplementation "com.squareup.spoon:spoon-client:$spoonClientVersion"
}
这是堆栈跟踪:
09-15 11:07:13.467 1129 1129 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/R$string;
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.google.android.gms.common.internal.StringResourceValueReader.<init>(Unknown Source)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.google.firebase.FirebaseOptions.fromResource(FirebaseOptions.java:156)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.google.firebase.FirebaseApp.initializeApp(FirebaseApp.java:244)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.google.firebase.provider.FirebaseInitProvider.onCreate(FirebaseInitProvider.java:51)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.content.ContentProvider.attachInfo(ContentProvider.java:1759)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.content.ContentProvider.attachInfo(ContentProvider.java:1734)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.google.firebase.provider.FirebaseInitProvider.attachInfo(FirebaseInitProvider.java:45)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread.installProvider(ActivityThread.java:6420)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread.installContentProviders(ActivityThread.java:6012)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5951)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread.-wrap3(ActivityThread.java)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1710)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.os.Looper.loop(Looper.java:154)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6776)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.R$string" on path: DexPathList[[zip file "/data/app/com.myestimates.buildercalcfree-2/base.apk"],nativeLibraryDirectories=[/data/app/com.myestimates.buildercalcfree-2/lib/arm, /system/lib, /vendor/lib]]
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
09-15 11:07:13.467 1129 1129 E AndroidRuntime: ... 18 more
也许这是一个常见的问题,但我不知道如何处理它。
谢谢
所以,经过几天的挖掘,我找到了解决方案。所以,为了让它发挥作用,我必须:
- 将AndroidGradle插件降级到3.5.3版本
- 将Gordon插件降级到1.0.6版本
- 已将 fabric-crashlytic 迁移到 firebase-crashlytic。加上最后一个插件,否则会出错
所有其他更新都可以设置,但这3项必须坚持提到的版本。