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'
}
关于android studio 出现Error:Execution failed for task ‘:app:preDebugAndroidTestBuild‘. 的解决办法
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 ...
解决小米手机Android Studio安装app 报错的问题It is possible that this issue is resolved by uninstalling an existi
问题描述 Android Studio升级到2.3版本之后,小米手机MIUI8不能运行Android Studio程序,报如下错误: [html] view plain copy Installation failed with message Failed to establish session
Found conflicts between different versions of the same dependent assembly that could not be resolved
https://stackoverflow.com/questions/24772053/found-conflicts-between-different-versions-of-the-same-dependent-assembly-that-c While the other response