烦人的Resolved versions for app (26.1.0) and test app (27.1.1) differ问题
Conflict with dependency‘com.android.support:support-annotations’ in project ‘:app’. Resolved versionsfor app (26.1.0) and test app (27.1.1) differ. Seehttps://d.android.com/r/tools/test-apk-dependency-conflicts.html for details....
这个错误很常见,几乎每个人都碰到过,
貌似是.build中的compileSdkVersion引起的,所依赖的dependency与当前版本不一致导致的。
一般的解决办法就是build->Rebuid-project。不过这样下次还是会冒出来。
参考方案
文献【1】给出了以下的方法,
在 app 的 build.gradle 中,在 android{...} 里添加如下代码:
configurations.all {
resolutionStrategy.force'com.android.support:support-annotations:27.1.1'
}
添加后的build.gradle(app)如下,重新make project,成功。
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.spacesoftwares.myapplication2"
minSdkVersion 21
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:27.1.1'
}
}
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'
}
文中提到的第二种方法,是在 app 的 build.gradle 中,在 android{...} 里,更改一下属性,使其为最近版本号,如下
andorid{
...
defaultConfig {
compileSdkVersion 27
defaultConfig {
...
targetSdkVersion 27
...
}
...
}
...
}
试了一下,这种方法貌似不能通过。
本人的办法
最后,本人的办法:在新建项目之后,一上来就改掉那个版本号,用最新的
android{
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
}
dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
}
整个build.gradle(module app)的配置如下
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.spacesoftwares.ssapplication"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
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'
}
【1】https://blog.csdn.net/sinat_30727215/article/details/80337799