用最新更新的android studio打开一个旧项目后,我对build.gradle文件有这个错误。我应该改变什么?
appcompact-v7依赖项出错: 所有com.android.support库必须使用完全相同的版本规范。找到版本26.1.0,19.1.0。
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "X"
minSdkVersion 15
targetSdkVersion 19
versionCode 7
versionName "name"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.1.0'
compile 'com.google.android.gms:play-services-ads:12.0.1'
}
答案 0 :(得分:1)
这样做: -
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "X"
minSdkVersion 15
targetSdkVersion 27
versionCode 7
versionName "name"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.0.3'
compile 'com.google.android.gms:play-services-ads:12.0.1'
}
答案 1 :(得分:0)
就像错误一样告诉你只需更改你的库版本:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.1.0' //19.1.0 to 27.1.0
compile 'com.google.android.gms:play-services-ads:12.0.1'
}
答案 2 :(得分:0)
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.google.android.gms:play-services-ads:12.0.1'
注意强>
如果你得到
Error:Failed to resolve: com.android.support:appcompat-v7:27.1.0'
然后在 PROJECT LEVEL google()
部分使用 build.gradle
。
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
// 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
}
Finally
模块级 build.gradle
将
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "X"
minSdkVersion 15
targetSdkVersion 27
versionCode 7
versionName "name"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.google.android.gms:play-services-ads:12.0.1'
}
然后 Clean-Rebuild-Run