今天更新到Android Studio 2.3后,我收到有关支持v4 jar版本冲突的错误,而我没有得到Android Studio 2.2。
所有com.android.support库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到的版本24.0.0,22.2.0。示例包括com.android.support:support-v4:24.0.0和com.android.support:recyclerview-v7:22.2。
这是我的gradle文件:
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.my.app"
minSdkVersion 17
targetSdkVersion 22
versionCode 12
versionName "2.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// we want to split the output apks across architectures
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a', 'mips', 'armeabi'
universalApk false
}
}
// Set the versionCode for each architecture (armeabi-v7a, x86, etc) to be unique. When defaultConfig.versionCode is updated, these generated codes will be updated accordingly/automatically, so we shouldn't need to change this code.
applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
output.versionCodeOverride =
project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) * 1000000 + android.defaultConfig.versionCode
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
compile 'com.bignerdranch.android:recyclerview-multiselect:0.2'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.caverock:androidsvg:1.2.1'
compile 'com.drewnoakes:metadata-extractor:2.8.1'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
compile 'com.google.android.gms:play-services-analytics:9.6.1'
compile 'com.google.android.gms:play-services-ads:9.6.1'
compile 'com.h6ah4i.android.widget.verticalseekbar:verticalseekbar:0.5.2'
compile files('libs/[third party library1].jar')
compile files('libs/[third party library2].jar')
compile project(':[third party project]')
compile files('libs/[third party library3].jar')
}
apply plugin: 'com.google.gms.google-services
如果我删除了com.google.android.gms:play-services-analytics:9.6.1
和com.google.android.gms:play-services-ads:9.6.1
,那么我就不会收到此错误,但我的项目也无法构建,因为我需要广告和分析。
有谁知道为什么会发生这种情况以及如何解决?在我的2.3更新之前是否可能存在此问题,但2.2没有报告此问题?
EDITED(2017-03-05)
在上面添加了完整的build.gradle
文件
我可以使用以下简化的build.gradle文件重现此错误:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "sharpened.com.testgoogleplay"
minSdkVersion 17
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services-analytics:9.6.1'
compile 'com.google.android.gms:play-services-ads:9.6.1'
}
使用项目构建文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}