我正在尝试将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.
有人遇到过这个吗?我发现它报告在这里,但没有解决方案。有人能解决这个问题吗?
新版本的 espresso-contrib 2.2.2
库现在依赖于com.android.support:appcompat-v7:23.1.1
,导致在compile
时间依赖中使用不同版本的appcompat-v7
时发生冲突,如下所示:
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'
}
为了避免冲突,当我们从espresso-contrib
中排除appcompat-v7
依赖时,它会因为design support
库的一些值依赖而再次中断。
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 . apppat . display1"匹配的资源。
因此,解决上述问题的方法是从espresso-contrib
中排除'design-support'库依赖,如下所示:
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'
}
解决了冲突问题!
更详细的答案可以查看我的其他答案
因此,经过大量的挖掘,我发现我需要更改支持注释的依赖项。
所以我需要改变compile 'com.android.support:support-annotations:22.2.0'
来androidTestCompile 'com.android.support:support-annotations:22.+'
最新版本的androidTest
依赖于相应版本的support-annotations
库。在我的例子中是:
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.gradle
, android{}
部分添加下一个代码:
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.0.1'
}
}
在Jake Wharton U2020应用程序中,它以以下方式解决
添加到您的gradle.build
文件
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.0.1'
}
}
在收到项目和测试应用之间类似的依赖冲突后,我不得不将以下版本合并为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
问题在这个文件中:android sdk android m2repository com 配件跑android 测试支持 0.3 runner-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,它将工作
如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
配置
只需将编译com.android.support:support-annotations:22.2.0
更改为23.0.1
如果想使用2.2.1版本