Android Espresso问题 - 依赖冲突

DJ-*_*DOO 18 android android-gradle-plugin 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')
}
Run Code Online (Sandbox Code Playgroud)

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

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

有没有遇到过这个?我发现它在这里报道但是没有解决方案.有人有解决方法吗?

Pun*_*itD 34

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

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'
}
Run Code Online (Sandbox Code Playgroud)

为了避免在我们appcompat-v7espresso-contrib下面排除依赖性时发生冲突,由于对design supportlib的某些值依赖性,它会再次中断.

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'
}
Run Code Online (Sandbox Code Playgroud)

错误:

错误:(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'
}
Run Code Online (Sandbox Code Playgroud)

这解决了冲突问题!

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


DJ-*_*DOO 10

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

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


Nik*_*hok 8

最新版本的androidTest依赖项取决于适当的support-annotationslib 版本.在我的情况下它是:

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'
Run Code Online (Sandbox Code Playgroud)

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

configurations.all {
   resolutionStrategy {
       force 'com.android.support:support-annotations:23.0.1'
   }
}
Run Code Online (Sandbox Code Playgroud)


htt*_*tch 7

Jake Wharton U2020应用程序中,它将以下一个方式解决

添加到您的gradle.build文件

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-annotations:23.0.1'
    }
}
Run Code Online (Sandbox Code Playgroud)