添加firebase-translate:22.0.0依赖后Gradle模块出现依赖解析异常
解决添加Firebase Translate依赖后的Gradle依赖解析错误
你遇到的这个依赖解析错误,核心问题是Firebase依赖版本管理混乱加上重复依赖、重复插件配置导致的。直接按下面的步骤修改你的Gradle文件就能解决:
1. 清理重复依赖
- 你重复引入了
com.google.android.material:material(1.7.0和1.2.0),删掉旧的1.2.0版本的依赖 - 你同时用了BoM管理Firebase版本,又手动指定了
firebase-auth:21.1.0,删掉这个带版本的依赖,保留BoM下方无版本的implementation 'com.google.firebase:firebase-auth'
2. 用Firebase BoM统一管理所有Firebase依赖版本
既然已经引入了Firebase BoM(com.google.firebase:firebase-bom:31.2.0),所有Firebase相关依赖都不要手动指定版本,让BoM自动匹配兼容版本,包括firebase-translate、firebase-database、firebase-messaging、firebase-ml-natural-language这些。
3. 移除重复的插件应用
文件末尾重复执行了apply plugin: 'com.google.gms.google-services'和apply plugin: 'com.android.application',删掉重复的这两行。
修改后的完整Gradle文件
plugins { id 'com.android.application' id 'com.google.gms.google-services' } android { compileSdk 32 defaultConfig { applicationId "com.isaacdarlong.myworshipresources" minSdk 28 targetSdk 32 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.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 'com.google.android.material:material:1.7.0' implementation 'com.firebaseui:firebase-ui-database:8.0.2' //implementation "androidx.recyclerview:recyclerview-selection:1.1.0" implementation "androidx.recyclerview:recyclerview:1.2.1" //implementation "androidx.recyclerview:recyclerview:1.3.1" //implementation "androidx.recyclerview:recyclerview:1.3.0-beta02" implementation "androidx.cardview:cardview:1.0.0" implementation 'com.github.bumptech.glide:glide:4.14.2' implementation 'de.hdodenhof:circleimageview:3.1.0' implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.4' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0' implementation 'com.squareup.picasso:picasso:2.8' implementation 'androidx.palette:palette:1.0.0' implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:11.1.0' implementation 'org.jsoup:jsoup:1.15.3' // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:31.2.0') // Firebase依赖全部由BoM管理版本,无需手动指定 implementation 'com.google.firebase:firebase-auth' implementation 'com.google.firebase:firebase-database' implementation 'com.google.firebase:firebase-messaging' implementation 'com.google.firebase:firebase-translate' implementation 'com.google.firebase:firebase-ml-natural-language' implementation 'com.google.firebase:firebase-ml-natural-language-translate-model' // Google Play services依赖指定版本 implementation 'com.google.android.gms:play-services-auth:20.4.1' implementation 'com.google.android.gms:play-services-location:21.0.1' implementation 'com.android.volley:volley:1.2.1' }
最后一步
修改完成后,点击Android Studio右上角的Sync Project with Gradle Files,同步完成后如果还有缓存问题,执行Build > Clean Project再Build > Rebuild Project即可。
内容的提问来源于stack exchange,提问作者Isaac Darlong
相关产品推荐
相关产品推荐

