You need to enable JavaScript to run this app. Android编译报错app:checkDebugDuplicateClasses重复类问题解决方案咨询
优惠活动
大模型
产品
解决方案
定价
更多

Android编译报错app:checkDebugDuplicateClasses重复类问题解决方案咨询

问题根源

你的构建报错是因为com.google.firebase:firebase-iid:21.0.1和com.google.firebase:firebase-messaging:22.0.0两个依赖包中都包含了com.google.firebase.iid.FirebaseInstanceIdReceiver类,出现了类重复冲突。同时你的模块级gradle中混用了指定版本的Firebase依赖和Firebase BOM依赖管理,也会导致依赖版本不匹配引发冲突。

解决方案

方案1:统一使用Firebase BOM管理所有Firebase依赖(最推荐)

BOM会自动匹配所有Firebase依赖的兼容版本,避免版本不匹配导致的冲突,修改你模块级build.gradle的dependencies部分:

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.navigation:navigation-fragment:2.3.5'
    implementation 'androidx.navigation:navigation-ui:2.3.5'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    // 移除Firebase依赖的版本号,交给BOM管理
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-messaging'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.preference:preference:1.1.1'

    implementation 'androidx.core:core:1.5.0'
    implementation 'androidx.drawerlayout:drawerlayout:1.1.1'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    // BOM放在所有Firebase依赖最前面
    implementation platform('com.google.firebase:firebase-bom:26.2.0')
    implementation 'com.google.firebase:firebase-analytics'

    implementation 'com.google.android.gms:play-services-location:18.0.0'

    implementation "androidx.security:security-crypto:1.0.0"

    // For Identity Credential APIs
    implementation "androidx.security:security-identity-credential:1.0.0-alpha02"
}

修改后同步Gradle,再Clean项目重新构建即可。

方案2:排除重复依赖

如果你不想调整BOM配置,可以直接在firebase-messaging依赖中排除重复的firebase-iid模块:

implementation ('com.google.firebase:firebase-messaging:22.0.0') {
    exclude group: 'com.google.firebase', module: 'firebase-iid'
}

方案3:强制指定依赖版本

也可以在模块级build.gradle的android节点外添加强制版本配置,统一firebase-iid的版本:

configurations.all {
    resolutionStrategy {
        force 'com.google.firebase:firebase-iid:21.0.1'
    }
}
验证操作

修改完成后依次执行:

  • 同步Gradle项目配置
  • 执行Build -> Clean Project
  • 执行Build -> Rebuild Project

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.19 13:15:06