【发布时间】:2018-11-07 15:17:29
【问题描述】:
我正在使用 android studio 3.0.1 在我创建新项目后它会给出以下错误:
错误:任务 ':app:preDebugAndroidTestBuild' 执行失败。
与项目 ':app' 中的依赖项 'com.android.support:support-annotations' 冲突。应用程序 (26.1.0) 和测试应用程序的已解决版本 (27.1.1) 不同。看 https://d.android.com/r/tools/test-apk-dependency-conflicts.html 为 详情。
这是我的应用级 build.gradle 文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 19
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'
}
}
}
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.0'
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'
}
这是我的顶级 build.gradle 文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
根据这篇文章: Error While creating new project with android studio 3.0.1
我改变了我的
implementation 'com.android.support:appcompat-v7:26.1.0'
到
implementation 'com.android.support:appcompat-v7:27.1.1'
但是因为我正在使用
targetSdkVersion 26
我不应该使用支持库 27.1.1。
我该如何解决这个问题
接受任何帮助。 谢谢你:)
【问题讨论】:
-
这里有多个相同的依赖问题,尝试排除一个。
-
targetSdkVersion与您的支持库版本无关。支持库版本与compileSdkVersion相关。如果compileSdkVersion是26,那么支持库版本应该是26.x.x,如果是27,那么支持库版本应该是27.x.x
标签: android android-studio build