“com.android.support:support-annotations”冲突

来源:互联网 发布:汉化软件安卓版下载 编辑:程序博客网 时间:2024/05/19 15:41

问题描述

嗨,我一直在使用Android支持v4 23.1.1,并最近尝试更新到23.3.0(最新的一个,当被问到),但我得到以下错误:

错误:与依赖关系“com.android.support:support-annotations”冲突。应用程序(23.3.0)和测试应用程序(23.1.1)的解决版本不同。有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict。

到目前为止,我发现这个https://code.google.com/p/android/issues/detail?id=206137

我去了两个链接,但我无法解决我的问题,我该如何解决这个问题?

编辑:

我有这些在我的依赖

compile 'com.android.support:support-v4:23.3.0'compile 'com.android.support:appcompat-v7:23.3.0'compile 'com.android.support:recyclerview-v7:23.3.0'compile 'com.android.support:cardview-v7:23.3.0'compile 'com.android.support:design:23.3.0'

Previouly所有版本都是23.1.1,它工作正常,更新后发生错误

编辑:

Gradle Version 2.10Gradle Plugin Version 2.0.0buildToolsVersion "23.0.3"

最佳解决思路

对于那些仍然面临这个问题的人,只需将这一行添加到你的依赖关系中即可。

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

它解决了我的问题。

次佳解决思路

对于那些仍然面临问题的人来说,上面的答案并没有帮助我在Android studio 2.2 Preview。

将其添加到您的毕业文件中。

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

这固定了我的问题。

参考:https://github.com/JakeWharton/u2020/blob/05a57bf43b9b61f16d32cbe8717af77cd608b0fb/build.gradle#L136-L140

第三种解决思路

仅仅是Akshayraj的答案

原始文件:

dependencies {    compile fileTree(include: ['*.jar'], dir: 'libs')    [...]    compile 'com.android.support:support-annotations:25.3.0'    androidTestCompile 'com.android.support.test:runner:0.5'    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'}

收到错误:

Error:Conflict with dependency ‘com.android.support:support-annotations’ in project ‘:app’.
Resolved versions for app (25.1.0) and test app (23.1.1) differ.
See http://g.co/androidstudio/app-test-app-conflict for details. “

当我补充说:

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

最终文件:

dependencies {    compile fileTree(include: ['*.jar'], dir: 'libs')    [...]    compile 'com.android.support:support-annotations:25.3.0'    androidTestCompile 'com.android.support:support-annotations:25.3.0'    androidTestCompile 'com.android.support.test:runner:0.5'    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'}

第四种思路

我的orignal app.gradle有:

dependencies {    // App dependencies    compile fileTree(dir: 'libs', include: ['*.jar'])    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:23.4.0'     // Testing-only dependencies    androidTestCompile 'com.android.support.test:runner:0.3'    androidTestCompile 'com.android.support.test:rules:0.3'    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'}

导致以下错误:错误:与依赖关系“com.android.support:support-annotations”冲突。应用程序(23.4.0)和测试应用程序(22.2.0)的解决版本不同。有关详细信息,请参阅http://g.co/androidstudio/app-test-app-conflict。

阅读错误后建议的链接,我发现这些行:

When instrumentation tests are run, both the main APK and test APK share the same classpath. Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions. If gradle didn’t catch that, your app could behave differently during tests and during normal run (including crashing in one of the cases).

所以我修改了我的app.gradle依赖项:

dependencies {    // App dependencies    compile fileTree(dir: 'libs', include: ['*.jar'])    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:23.4.0'    // Testing-only dependencies    androidTestCompile 'com.android.support:support-annotations:23.3.0'    androidTestCompile 'com.android.support.test:runner:0.3'    androidTestCompile 'com.android.support.test:rules:0.3'    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'}

即使在上述变化之后,gradle也不开心:-(:错误:与依赖关系相冲突com.android.support:support-annotations’。应用程序(23.4.0)和测试应用程序(23.3.0)的解决版本不同,请参见http://g.co/androidstudio/app-test-app-conflict细节。

测试apk版本的变化是不同的!所以我修改了下面粘贴的版本字符串:

(涅磐)

dependencies {    // App dependencies    compile fileTree(dir: 'libs', include: ['*.jar'])    testCompile 'junit:junit:4.12'    compile 'com.android.support:appcompat-v7:23.4.0' // main APK    // Testing-only dependencies    androidTestCompile 'com.android.support:support-annotations:23.4.0' //test APK    androidTestCompile 'com.android.support.test:runner:0.3'    androidTestCompile 'com.android.support.test:rules:0.3'    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'}

第五种思路

您必须对应用程式和AndroidTest APK使用相同的版本。为此,请指定与您的应用程序相同的版本,

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

其中24.1.1是应用程序中使用的依赖关系的版本号

第六种思路

compile 'com.android.support:design:24.1.1'

参考文献

  • Android support library error after updating to 23.3.0

注:本文内容整合自google/baidu/bing辅助翻译的英文资料结果。如果您对结果不满意,可以加入我们改善翻译效果:gxnotes#qq.com(#替换为@)。

本文由《共享笔记》整理, 博文地址: https://gxnotes.com/article/219588.html,未经允许,请勿转载。
原创粉丝点击