首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与依赖关系“com.android.Support:support-注释”冲突。app (23.1.0)和测试app (23.0.1)的解析版本不同

与依赖关系“com.android.Support:support-注释”冲突。app (23.1.0)和测试app (23.0.1)的解析版本不同
EN

Stack Overflow用户
提问于 2015-10-24 11:17:12
回答 9查看 111.4K关注 0票数 119

在构建时,我会得到以下错误:

代码语言:javascript
复制
Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (23.1.0) and test app (23.0.1) differ.

这些是我的gradle依赖关系

代码语言:javascript
复制
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'
}

我怎么才能解决这个问题?

EN

回答 9

Stack Overflow用户

回答已采纳

发布于 2015-10-24 12:57:53

可以使用以下命令在测试中强制使用注释库:

代码语言:javascript
复制
androidTestCompile 'com.android.support:support-annotations:23.1.0'

就像这样:

代码语言:javascript
复制
  // 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'

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

代码语言:javascript
复制
configurations.all {
    resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'
}
票数 208
EN

Stack Overflow用户

发布于 2018-05-03 10:20:56

重建工程解决了我的问题。

在Android工作室中的工具栏..。Build>Rebuild项目。

票数 69
EN

Stack Overflow用户

发布于 2016-07-18 12:30:30

来源:用Espresso进行CodePath - UI测试

  1. 最后,我们需要引入Espresso依赖项,并在我们的应用程序build.gradle中设置测试运行程序:
代码语言:javascript
复制
// build.gradle
...
android {
    ...
    defaultConfig {
        ...
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}

dependencies {
    ...
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
        // Necessary if your app targets Marshmallow (since Espresso
        // hasn't moved to Marshmallow yet)
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    androidTestCompile('com.android.support.test:runner:0.5') {
        // Necessary if your app targets Marshmallow (since the test runner
        // hasn't moved to Marshmallow yet)
        exclude group: 'com.android.support', module: 'support-annotations'
    }
}

我把它加到我的gradle文件里,警告就消失了。

此外,如果您得到任何其他冲突的依赖项,例如支持注释,请尝试将其排除在androidTestCompile依赖项之外。

票数 25
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33317555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档