You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio构建报错求助:应用运行时构建失败排查

问题排查与解决方案

从构建错误截图来看,核心问题是重复类冲突,源于Google Play服务依赖版本不兼容:你同时引入了旧版完整的play-services:12.0.1包,以及更高版本的拆分模块(play-services-auth:20.5.0、play-services-gcm:17.0.0),这些库内部包含相同类的不同版本,导致构建失败。

修复步骤:

  1. 移除旧版完整Play服务依赖
    删除dependencies中的这一行:

    implementation 'com.google.android.gms:play-services:12.0.1'
    

    现在Google Play服务已拆分为独立模块,只需引入你实际需要的模块即可,完整包会导致冗余和版本冲突。

  2. 引入Google BOM统一版本管理
    在dependencies最顶部添加Google服务的BOM,自动同步所有Play服务和Firebase库的兼容版本:

    implementation platform('com.google.firebase:firebase-bom:32.7.0')
    

    这样你可以移除Firebase和Play服务依赖的版本号,由BOM统一管理,避免版本不匹配。

  3. 调整Firebase依赖写法
    原Firebase核心依赖可以简化为:

    implementation 'com.google.firebase:firebase-core'
    

    版本号由BOM自动控制。

修改后的完整dependencies示例:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation project(':PGSDKVR4')
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation 'com.google.code.gson:gson:2.8.9'
    implementation 'com.github.bumptech.glide:glide:4.12.0'
    implementation 'androidx.recyclerview:recyclerview:1.3.0'
    implementation 'com.google.android.material:material:1.9.0'
    implementation 'com.android.volley:volley:1.2.1'
    implementation 'com.facebook.android:facebook-android-sdk:4.37.0'

    // 引入Google BOM统一版本
    implementation platform('com.google.firebase:firebase-bom:32.7.0')
    //Firebase
    implementation 'com.google.firebase:firebase-core'

    //play-services
    implementation 'com.google.android.gms:play-services-auth'
    implementation 'com.google.android.gms:play-services-gcm'
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    implementation 'com.joooonho:selectableroundedimageview:1.0.1'
    implementation 'com.paytm:pgplussdk:1.1.3'
    implementation 'com.payumoney.sdkui:plug-n-play:1.4.5'
    implementation 'androidx.multidex:multidex:2.0.1'
    implementation project(':cashfreeSDK')
    implementation 'com.github.ybq:Android-SpinKit:1.4.0'
    implementation 'com.loopeer.lib:shadow:0.0.4-beta3'
    implementation("net.orandja.shadowlayout:shadowlayout:1.0.1")
    implementation 'com.mikhaellopez:circularimageview:4.3.1'
    implementation 'com.github.GrenderG:Toasty:1.5.2'
    implementation 'com.hbb20:ccp:2.7.0'
    implementation ("androidx.browser:browser:1.5.0")
}
  1. 同步项目并重新构建
    点击Android Studio右上角的"Sync Project with Gradle Files"按钮,同步完成后尝试重新运行应用。

额外提示:

  • 检查facebook-android-sdk:4.37.0是否与compileSdkVersion 33兼容,若后续出现相关警告,可考虑升级到更近期的版本。
  • 确保PGSDKVR4和cashfreeSDK两个本地模块的依赖版本也与主项目兼容,避免二次冲突。

内容的提问来源于stack exchange,提问作者SaAsh Techs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 19:53:17