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

Android Studio编译执行失败:依赖冲突问题求助

解决Android项目中support-annotations依赖冲突问题

我之前也碰到过一模一样的问题,核心就是测试模块和主应用的support-annotations依赖版本不匹配,导致构建任务:app:preDebugAndroidTestBuild执行失败。下面给你几个实用的解决办法:

  • 强制统一所有模块的依赖版本
    在app模块的build.gradle文件中添加配置,强制让所有模块(包括测试模块)使用同一个版本的support-annotations:

    configurations.all {
        resolutionStrategy.force 'com.android.support:support-annotations:26.1.0'
    }
    

    这里选择26.1.0是因为你的主应用使用的是这个版本,如果你想升级主应用到27.1.1也可以,只要保证两边版本一致就行。

  • 手动调整测试依赖的版本
    检查你的androidTestDependencies,找到间接引入27.1.1版本support-annotations的依赖,先排除冲突的部分,再手动引入统一版本。比如:

    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestImplementation 'com.android.support:support-annotations:26.1.0'
    
  • 升级主应用的Support库版本
    如果项目允许,直接把主应用中所有相关的Support库(比如appcompat-v7、design等)版本统一升级到27.1.1,让测试模块和主应用的依赖版本完全一致,冲突自然就解决了。

简单说,这个问题的本质就是Gradle在解析主应用和测试应用的依赖时,发现support-annotations的版本不一致,无法确定使用哪个版本,只要让两边版本统一就能搞定。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 07:04:54