android - 与依赖项 'com.android.support:support-annotations' 冲突。应用程序 (23.1.0) 和测试应用程序 (23.0.1) 的已解决版本不同

标签 android gradle android-gradle-plugin build.gradle android-espresso

构建时出现以下错误:

Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.1.0) and test app (23.0.1) differ.

这些是我的 gradle 依赖项

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.squareup:otto:1.3.8'
    compile 'com.snappydb:snappydb-lib:0.5.2'
    compile 'com.esotericsoftware.kryo:kryo:2.24.0'
    compile 'com.google.dagger:dagger:2.0.1'
    apt 'com.google.dagger:dagger-compiler:2.0.1'
    compile 'javax.annotation:javax.annotation-api:1.2'
    compile 'io.reactivex:rxandroid:1.0.1'
    compile 'io.reactivex:rxjava:1.0.14'
    compile 'com.google.android.gms:play-services-location:8.1.0'
    compile 'com.google.android.gms:play-services-gcm:8.1.0'
    compile 'org.apache.commons:commons-lang3:3.4'
    testCompile 'junit:junit:4.12'
    testCompile 'org.hamcrest:hamcrest-library:1.3'
    testCompile 'org.mockito:mockito-core:1.10.19'
    androidTestCompile 'com.android.support.test:runner:0.4'
    androidTestCompile 'com.android.support.test:rules:0.4'
    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'
    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
}

我该如何解决这个问题?

最佳答案

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

androidTestCompile 'com.android.support:support-annotations:23.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:23.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:23.1.0'
}

关于android - 与依赖项 'com.android.support:support-annotations' 冲突。应用程序 (23.1.0) 和测试应用程序 (23.0.1) 的已解决版本不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33317555/

相关文章:

android - LintOption 基线错误

android - 使用不同的 android API 编译不同的 android 模块

android - Android 移动应用程序的基于兴趣和位置的算法

android - 构建期间找不到 Github 包

plugins - Gradle 自定义插件的构建抛出 "unable to resolve class"

android - 如何在gradle中设置对其他口味的依赖

java - 渲染大 Bitmap 的小区域非常耗时

android - 如何在 MultiSelectListPreference 中设置多个默认值?

java - Jenkins :建立对其他工件/项目的依赖的工作

android - 在 jCenter 中分发 Android 库以在 gradle 中使用