Android Espresso问题 - 依赖冲突

时间:2015-08-04 10:43:40

标签: android android-gradle android-espresso

我正在尝试将espresso集成到我的ui测试应用程序中。这是我在Gradle中的依赖

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.1'
    compile 'com.github.bumptech.glide:okhttp-integration:1.3.1@aar'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'de.hdodenhof:circleimageview:1.3.0'
    compile 'com.android.support:cardview-v7:21.+'
    compile 'com.android.support:recyclerview-v7:21.+'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2'
    compile 'com.android.support:support-annotations:22.2.0'
    androidTestCompile 'com.android.support.test:runner:0.3'
    compile project(':common')
    compile project(':service')
}

所以我的espresso依赖项都包括在内。但是,当我尝试构建时,我收到此错误:

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

有没有人遇到过这个?我发现它报告here但是没有解决方案。有人有解决方法吗?

8 个答案:

答案 0 :(得分:34)

espresso-contrib 2.2.2 库的新版本现在依赖于com.android.support:appcompat-v7:23.1.1,因此在appcompat-v7时间依赖项中使用不同版本的compile时会产生冲突如下所示:

dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     testCompile 'junit:junit:4.12'
     compile 'com.android.support:appcompat-v7:23.4.0'

     androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
}

为了避免在我们从appcompat-v7排除espresso-contrib依赖关系时发生冲突,由于design support lib的某些值依赖性,它会再次中断。

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'support-v13'
    exclude module: 'recyclerview-v7'
    exclude module: 'appcompat-v7'
}

错误:

  

错误:(69)检索项目的父项时出错:找不到与给定名称“TextAppearance.AppCompat.Display1”匹配的资源。

因此,上述问题的解决方案是从espresso-contrib中排除“设计支持”lib依赖性,如下所示:

androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2'){
    exclude module: 'support-annotations'
    exclude module: 'support-v4'
    exclude module: 'support-v13'
    exclude module: 'recyclerview-v7'
    exclude module: 'design'
}

解决了冲突问题!

有关答案的更详细版本,您可以查看我的其他answer

答案 1 :(得分:10)

因此经过大量的挖掘后,我发现我需要更改支持注释的依赖性。

所以我需要改变 compile 'com.android.support:support-annotations:22.2.0'androidTestCompile 'com.android.support:support-annotations:22.+'

答案 2 :(得分:8)

androidTest依赖项的最新版本取决于support-annotations lib的适当版本。就我而言,它是:

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 'org.mockito:mockito-core:2.0.31-beta'

此外,作为解决方法,您可以在build.gradleandroid{}部分添加下一个代码:

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

答案 3 :(得分:7)

Jake Wharton U2020 application中,它将以下一个方式解决

添加到您gradle.build文件

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

答案 4 :(得分:4)

在项目和测试应用程序之间收到类似的依赖性冲突后,我必须将以下版本用于L版本:

android {
    useLibrary 'org.apache.http.legacy'
    compileSdkVersion 23
    buildToolsVersion '23.0.1'
    defaultConfig {    
        minSdkVersion 14
        targetSdkVersion 23
    }
}
dependencies {
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:support-v4:23.0.1'

    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'
}
由于我们使用org.apache.http导入,因此需要使用useLibrary,请参阅https://github.com/bitstadium/HockeySDK-Android/issues/80

答案 5 :(得分:1)

问题出在这个文件中: Android的SDK \额外\机器人\ m2repository \ COM \机器人\支持\测试\转轮\ 0.3 \亚军0.3.pom

这里:

<dependency>
      <groupId>com.android.support</groupId>
      <artifactId>support-annotations</artifactId>
      <version>22.2.0</version>
      <scope>compile</scope>
</dependency>

如果你设置22.2.1而不是22.2.0它将起作用

答案 6 :(得分:1)

如google文档中所述: https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Resolving-conflicts-between-main-and-test-APK

解决方法是将androidTestCompile中的支持库明确设置为您在项目中使用的版本。

如果您使用支持库版本25.0.1,则只需添加

androidTestCompile 'com.android.support:support-annotations:25.0.1'
您的build.gradle配置

中的

答案 7 :(得分:0)

只需将编译com.android.support:support-annotations:22.2.0更改为23.0.1 如果想使用2.2.1版本