报错:
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.
截图:
解决方法:
1.点击Build - Rebuild project,错误消除,但是重启AS,再次打开项目的时候还会出现该错误,虽然不影响,但是看着难受。
2.错误大致意思为,依赖冲突,可以看到,依赖项里面,annotation有两个,一个26.1.0另一个为27.1.1
3.解决方式一:在app - build.gradle dependencies{}节点下增加如下内容:
androidTestCompile('com.android.support:support-annotations:26.1.0') {
force = true
}
4.解决方式二:在app - build.gradle Android{}节点下增加如下内容:
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:26.1.0'
}
完整例子:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "club.pogaizai.del2"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
//方式一
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:26.1.0'
}
}
dependencies {
//方式二
androidTestCompile('com.android.support:support-annotations:26.1.0') {
force = true
}
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
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'
}