Android应用出现Cannot resolve symbol 'InternalAppCheckTokenProvider'错误求助
解决Firebase依赖冲突导致的
java.lang.NoClassDefFoundError错误 项目此前运行正常,今日调试时Gradle构建无异常,但在模拟器上运行应用出现以下错误:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/firebase/appcheck/interop/InternalAppCheckTokenProvider;
项目build.gradle配置如下:
plugins { id 'com.android.application' id 'com.google.gms.google-services' } android { namespace 'com.sao.myapp' compileSdk 33 defaultConfig { applicationId "com.sao.myapp" minSdk 21 targetSdk 33 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { implementation 'androidx.cardview:cardview:1.0.0' //noinspection GradleCompatible implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:21.3.0' implementation platform('com.google.firebase:firebase-bom:31.5.0') implementation 'com.github.TutorialsAndroid:GButton:v1.0.19' implementation 'com.google.android.gms:play-services-auth:20.5.0' implementation 'com.github.bumptech.glide:glide:4.12.0' implementation 'com.google.firebase:firebase-auth-ktx:22.0.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' implementation 'com.google.firebase:firebase-database-ktx:20.2.1' implementation 'com.google.android.gms:play-services-auth:20.5.0' implementation 'com.google.android.material:material:1.8.0' implementation 'de.hdodenhof:circleimageview:3.1.0' //Firebase kütüphaneleri implementation 'com.google.firebase:firebase-analytics-ktx' implementation "androidx.constraintlayout:constraintlayout:2.1.4" implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.firebase:firebase-database' implementation 'com.google.firebase:firebase-storage' implementation 'com.google.firebase:firebase-auth' testImplementation 'junit:junit:4.13.2' //noinspection GradleCompatible androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }
问题根源与解决方案
1. 统一Firebase依赖版本
你同时使用了Firebase BOM和手动指定版本的Firebase库(如firebase-auth-ktx:22.0.0),这会导致版本不兼容。Firebase BOM的作用就是统一管理所有Firebase库的兼容版本,因此需要移除手动指定的版本号,让BOM自动管理。
2. 清理重复依赖
依赖中重复添加了com.google.android.gms:play-services-auth:20.5.0,需删除其中一个。
3. 解决AndroidX与Support库冲突
项目同时混用了com.android.support和androidx开头的库(如appcompat-v7:28.0.0和androidx.appcompat:1.6.1),这两个体系无法共存,需完全迁移到AndroidX,移除所有com.android.support开头的依赖。
4. 修复错误的依赖版本
com.android.support.constraint:constraint-layout:21.3.0版本格式错误,直接替换为AndroidX版本即可。
修改后的完整dependencies代码
dependencies { implementation 'androidx.cardview:cardview:1.0.0' // 完全使用AndroidX库 implementation 'androidx.appcompat:appcompat:1.6.1' implementation "androidx.constraintlayout:constraintlayout:2.1.4" // Firebase BOM统一管理版本 implementation platform('com.google.firebase:firebase-bom:31.5.0') implementation 'com.github.TutorialsAndroid:GButton:v1.0.19' implementation 'com.google.android.gms:play-services-auth:20.5.0' implementation 'com.github.bumptech.glide:glide:4.12.0' // 移除手动指定的版本号,由BOM管理 implementation 'com.google.firebase:firebase-auth-ktx' implementation 'com.google.firebase:firebase-database-ktx' annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0' implementation 'com.google.android.material:material:1.8.0' implementation 'de.hdodenhof:circleimageview:3.1.0' // Firebase库统一由BOM管理版本 implementation 'com.google.firebase:firebase-analytics-ktx' implementation 'com.google.firebase:firebase-database' implementation 'com.google.firebase:firebase-storage' implementation 'com.google.firebase:firebase-auth' testImplementation 'junit:junit:4.13.2' // 迁移到AndroidX测试库 androidTestImplementation 'androidx.test:runner:1.5.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' }
后续操作
- 点击Android Studio右上角的
Sync Project with Gradle Files同步项目 - 执行
Build > Clean Project清理项目缓存 - 执行
Build > Rebuild Project重新构建项目 - 重启模拟器后重新运行应用
内容的提问来源于stack exchange,提问作者Ayça Oktay
相关产品推荐
相关产品推荐

