Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
使用AndroidStudio 新建项目时出现如下图:
http://stackoverflow.com/questions/28999124/resolved-versions-for-app-22-0-0-and-test-app-21-0-3-diffe给出了一些解释:
+--- com.android.support.test:testing-support-lib:0.1 (*) \--- com.android.support.test.espresso:espresso-contrib:2.0 +--- com.android.support:recyclerview-v7:21.0.3 | +--- com.android.support:support-annotations:21.0.3 | \--- com.android.support:support-v4:21.0.3 | \--- com.android.support:support-annotations:21.0.3 +--- com.android.support:support-v4:21.0.3 (*) \--- com.android.support.test.espresso:espresso-core:2.0 (*)
com.android.support:support-annotations这个依赖冲突了,app里的版本是26.1.0,但是Test app的版本里是27.1.1。
就是你测试编译版本中包含27.1.1的引用,而你的项目正式环境编译最多支持到26.1.0
方法一:
把build文件中引用包含27.1.1的jar包注释就好了
方法二:
在build.gradle中加上configurations.all代码,强行指定版本为26.1.0(更推荐使用)
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:26.1.0'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
帮到你就点个喜欢吧