Android Espresso 问题 - 依赖冲突
Android Espresso Issue - Dependency conflict
我正在尝试将浓缩咖啡集成到我的应用程序中以进行 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')
}
所以我所有的浓缩咖啡依赖项都包括在内。但是,当我尝试 build 时,出现此错误:
Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.2.1) and test app (22.2.0) differ.
有人遇到过这种情况吗?我发现它报告 here 但是没有解决方案。有人对此有解决办法吗?
所以经过大量的挖掘,我发现我需要更改支持注释的依赖关系。
所以我需要改变
compile 'com.android.support:support-annotations:22.2.0'
到
androidTestCompile 'com.android.support:support-annotations:22.+'
问题出在这个文件中:
android-sdk\extras\android\m2repository\com\android\support\test\runner[=17=].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,它将起作用
在收到项目和测试应用程序之间的类似依赖冲突后,我不得不将以下版本合并为 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'
}
useLibrary 是必需的,因为我们使用 org.apache.http 导入,参见 https://github.com/bitstadium/HockeySDK-Android/issues/80
在Jake Wharton U2020 application中用下面的方法解决
添加到你的gradle.build
文件
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.0.1'
}
}
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'
}
}
espresso-contrib 2.2.2
库的新版本现在依赖于 com.android.support:appcompat-v7:23.1.1
,导致在 [=] 中使用不同版本的 appcompat-v7
时发生冲突16=] 如下所示的时间依赖性:
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
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'
}
错误:
Error:(69) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'.
因此,上述问题的解决方案是从 espresso-contrib
中排除 'design-support' lib depedency,如下所示:
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'
}
冲突问题解决了!
更详细的答案可以查看我的另一个
只需将编译 com.android.support:support-annotations:22.2.0
更改为 23.0.1
如果要使用2.2.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
配置中
我正在尝试将浓缩咖啡集成到我的应用程序中以进行 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')
}
所以我所有的浓缩咖啡依赖项都包括在内。但是,当我尝试 build 时,出现此错误:
Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.2.1) and test app (22.2.0) differ.
有人遇到过这种情况吗?我发现它报告 here 但是没有解决方案。有人对此有解决办法吗?
所以经过大量的挖掘,我发现我需要更改支持注释的依赖关系。
所以我需要改变
compile 'com.android.support:support-annotations:22.2.0'
到
androidTestCompile 'com.android.support:support-annotations:22.+'
问题出在这个文件中: android-sdk\extras\android\m2repository\com\android\support\test\runner[=17=].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,它将起作用
在收到项目和测试应用程序之间的类似依赖冲突后,我不得不将以下版本合并为 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'
}
useLibrary 是必需的,因为我们使用 org.apache.http 导入,参见 https://github.com/bitstadium/HockeySDK-Android/issues/80
在Jake Wharton U2020 application中用下面的方法解决
添加到你的gradle.build
文件
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.0.1'
}
}
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'
}
}
espresso-contrib 2.2.2
库的新版本现在依赖于 com.android.support:appcompat-v7:23.1.1
,导致在 [=] 中使用不同版本的 appcompat-v7
时发生冲突16=] 如下所示的时间依赖性:
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
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'
}
错误:
Error:(69) Error retrieving parent for item: No resource found that matches the given name 'TextAppearance.AppCompat.Display1'.
因此,上述问题的解决方案是从 espresso-contrib
中排除 'design-support' lib depedency,如下所示:
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'
}
冲突问题解决了!
更详细的答案可以查看我的另一个
只需将编译 com.android.support:support-annotations:22.2.0
更改为 23.0.1
如果要使用2.2.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
配置中