【问题标题】:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.3.0) and test app (23.1.1) differ与依赖项“com.android.support:support-annotations”冲突。应用程序 (23.3.0) 和测试应用程序 (23.1.1) 的已解决版本不同
【发布时间】:2016-08-02 08:14:57
【问题描述】:

我在将 espresso 添加到 android 项目时遇到了这个异常。我已经尝试了这个异常附带的链接

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

我也根据我找到的其他线程添加以下行

**androidTestCompile 'com.android.support:support-annotations:23.1.0'**

但问题仍然存在。我正在使用以下配置:

buildToolsVersion "23.0.2"

androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'

任何想法,谢谢。

【问题讨论】:

标签: android android-studio-2.0


【解决方案1】:

这为我解决了“应用程序 (24.0.0-beta1) 和测试应用程序 (23.0.1) 的已解决版本不同”的问题。

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

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

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

【讨论】:

  • 这是唯一对我有用的答案。必须将configurations.all 放在 dependencies 块的底部。
【解决方案2】:
dependencies {
    //...

    // Solves "versions for app (23.3.0) and test app (23.1.1) differ"
    androidTestCompile 'com.android.support:support-annotations:23.3.0'

    // Android JUnit Runner
    androidTestCompile 'com.android.support.test:runner:0.5'
    // JUnit4 Rules
    androidTestCompile 'com.android.support.test:rules:0.5'
}

【讨论】:

  • 可能是关于另一个库?为 androidTestCompile 添加所有 com.android.support... 库
  • 谢谢... androidTestCompile 'com.android.support:support-annotations:XX.XX.XX' 你的应用版本
  • Gradle 构建良好,但对于不同版本的支持库版本,androidTestCompile 'com.android.support.test:rules:0.5' 显示错误
【解决方案3】:

现在,当你在 Android Studio 上创建一个新项目时,它会默认添加此依赖项:

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

exclude 部分可能是为了避免问题中提到的冲突。我在尝试添加 runner:0.5 和 rules:0.5 依赖项时也遇到了这个问题。我的解决方案是对它们应用上面相同的代码:

androidTestCompile ('com.android.support.test:runner:0.5', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

androidTestCompile ('com.android.support.test:rules:0.5', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

它对我有用。希望对您有所帮助。

【讨论】:

    【解决方案4】:

    注释库被所有三个依赖规则使用:0.5'、runner:05 和 espresso-core:2.2.2,所以以下对我有用

    androidTestCompile 'com.android.support.test:runner:0.5', {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestCompile 'com.android.support.test:rules:0.5', {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    

    【讨论】:

      【解决方案5】:

      重建项目解决了这个问题。

      在Android studio的工具栏中.. Build>Rebuild Project.

      【讨论】:

        【解决方案6】:
        сompile 'com.android.support:support-annotations:23.3.0'
        androidTestCompile ("com.android.support.test:runner:0.5"){
           exclude group: 'com.android.support'
        }
        androidTestCompile ('com.android.support.test:rules:0.5'){
           exclude group: 'com.android.support'
        }
        

        解决办法

        【讨论】:

        • 为什么这样可以解决问题?我不明白。我试过了,它没有解决任何问题。
        • 我的依赖版本: androidGradleToolsVersion = '2.1.0' androidBuildToolsVersion = '23.0.2' androidSDKVersion = 23 androidSupportLibVersion = '23.3.0' 尝试改变它。或者尝试使用最新版本。但我认为你仍然需要使用上面的一段代码。
        猜你喜欢
        • 1970-01-01
        • 2023-03-12
        • 2018-10-11
        • 2017-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-12
        • 2018-10-11
        相关资源
        最近更新 更多