【问题标题】:gradle Build Error: Conflict with dependency 'com.android.support:support-annotations'gradle 构建错误:与依赖项 'com.android.support:support-annotations' 冲突
【发布时间】:2018-02-03 15:26:42
【问题描述】:
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.

与项目 ':app' 中的依赖项 'com.android.support:support-annotations' 冲突。应用 (26.1.0) 和测试应用的已解决版本

Gradle Build 后这个错误是什么?

【问题讨论】:

  • 发布你的整个 gradle 文件

标签: android debugging gradle build


【解决方案1】:

在 gradle 中添加这些行来解决问题:- 下面的行强制使用注释库版本到 26.1.0。

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

如果你想运行 AndroidTest,别忘了添加以下代码

 defaultConfig {
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

【讨论】:

    【解决方案2】:

    您可以在测试中强制使用注释库:

    androidTestCompile 'com.android.support:support-annotations:26.1.0'
    

    类似这样的:

    // Force usage of support annotations in the test app, since it is internally used by the runner module.
    
      androidTestCompile 'com.android.support:support-annotations:26.1.0'
      androidTestCompile 'com.android.support.test:runner:0.4.1'
      androidTestCompile 'com.android.support.test:rules:0.4.1'
      androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
      androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
      androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.1'
    

    另一种解决方案是在顶级文件中使用它:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-12
      • 2018-11-20
      • 1970-01-01
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多