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

运行Android应用时出现Program type already present: CoordinatorLayout$Behavior错误

解决「Program type already present: android.support.design.widget.CoordinatorLayout$Behavior」错误

嘿,这个问题我太熟悉了——你碰到的是典型的Android依赖冲突:你的项目里同一类被多个不同版本的依赖包同时引入,导致编译时冲突。具体来说,android.support.design库被重复加载了:你手动指定的appcompat-v7:26.1.0和Firebase 15.0.0系列依赖内部自带的Support库版本不匹配,两边的CoordinatorLayout$Behavior类撞车了。

给你两个靠谱的解决方案,优先选第一个:

方案1:统一Support库版本(推荐)

Firebase 15.0.0版本有严格的Support库版本要求,必须配套27.1.1版本的Support库。你只需要把所有Support相关依赖统一到这个版本就行:

修改你的模块级build.gradle依赖配置:

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    // 替换成Firebase要求的Support库版本
    implementation 'com.android.support:appcompat-v7:27.1.1'
    // 显式引入design库(避免隐式依赖带来的版本不一致)
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.firebase:firebase-auth:15.0.0'
    implementation 'com.google.firebase:firebase-storage:15.0.0'
    testImplementation 'junit:junit:4.12'
    // 别忘了把androidTest里的Support依赖也同步改成对应版本,比如:
    // androidTestImplementation 'com.android.support.test:runner:1.0.2'
    // androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

方案2:强制所有依赖使用指定版本

如果暂时不想升级Support库版本,可以在项目根目录的build.gradle里添加强制统一规则,让所有依赖都乖乖用你指定的版本:

在allprojects块里加入这段配置:

allprojects {
    repositories {
        google()
        jcenter()
    }
    // 强制所有依赖使用指定的Support库版本
    configurations.all {
        resolutionStrategy {
            force 'com.android.support:design:26.1.0'
            force 'com.android.support:appcompat-v7:26.1.0'
            // 其他冲突的Support库也可以在这里添加强制规则
        }
    }
}

额外小技巧:排查依赖冲突根源

你可以通过Android Studio自带的工具查看完整依赖树,精准定位哪个依赖引入了冲突版本:

  1. 打开右侧的Gradle面板,找到你的项目 → Tasks → android → androidDependencies
  2. 双击运行这个任务,在控制台输出里搜索android.support.design,就能看到所有引入该库的依赖及其版本号。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:57:05