android - 依赖冲突 'com.android.support:support-annotations'

标签 android unit-testing android-testing android-instrumentation

我正在尝试为我的应用程序设置仪表化单元测试。我已经根据下面的开发者网站链接添加了依赖项。

https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests.html#build

这是我的依赖项列表

dependencies {
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:support-v4:21.0.3'
    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'
    androidTestCompile 'com.android.support:support-annotations:24.0.0'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
}

当我构建项目时,我收到以下编译错误:

Error:Conflict with dependency 'com.android.support:support-annotations' in project ':MyApp'. Resolved versions for the app (21.0.3) and test app (24.0.0) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

有人可以帮我解决这个问题吗?

最佳答案

注释是支持库的一部分。所以,你的注解和支持库版本应该是相同的,你必须使用下面的代码强制调用。此代码应该放在依赖项之上。更多详细信息 See here

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

关于android - 依赖冲突 'com.android.support:support-annotations',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46419837/

相关文章:

android - 以编程方式更改android布局

android - 如何在 Android 中的视频上渲染 Web Kit 内容?

java - 如何让ZXing在android中的部分 Activity (而不是全屏)中显示?

android - 在 Android 中从 Google 电子表格查询数据

unit-testing - 测试类似的逻辑

c# - UrlHelper 类在 Asp.net mvc 中抛出空异常

unit-testing - 针对条件 (A && B && C) || 执行 MCDC D

android - 找到路径为 'META-INF/LGPL2.11' 的 2 个文件

android-studio - 使用AndroidTestOrchestrator进行的调试在等待调试器时卡住

android - AndroidJUnitRunner 1.0.0 和 AssertJ 的仪器化测试失败