android - Android gradle 错误:所有 com.android.support 库必须使用完全相同的版本规范?
问题描述
你可以在 stackoverflow 上找到几十个同名的问题。不幸的是,这些都没有解决我的问题。
我收到以下错误:
所有 com.android.support 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 26.1.0、25.3.1。示例包括com.android.support:support-compat:26.1.0
和com.android.support:animated-vector-drawable:25.3.1
在这一行(模块应用程序):
compile "com.android.support:appcompat-v7:$android_support_version"
但我不明白为什么?我在哪里使用版本 26.1.0?
这是我的文件(项目文件):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
android_support_version ="25.3.1"
archVersion = "1.0.0-alpha3"
}
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
模块应用:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
defaultConfig {
applicationId "com.bsobat.github"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
dataBinding {
enabled = true
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:appcompat-v7:$android_support_version"
compile "com.android.support:support-v13:$android_support_version"
compile "com.android.support:design:$android_support_version"
compile "com.android.support:recyclerview-v7:$android_support_version"
compile "com.android.support:cardview-v7:$android_support_version"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
//dagger2
compile "com.google.dagger:dagger:2.9"
annotationProcessor "com.google.dagger:dagger-compiler:2.9"
provided 'javax.annotation:jsr250-api:1.0'
compile 'javax.inject:javax.inject:1'
//android arch. component
compile "android.arch.lifecycle:runtime:$archVersion"
compile "android.arch.lifecycle:extensions:$archVersion"
annotationProcessor "android.arch.lifecycle:compiler:$archVersion"
compile "android.arch.persistence.room:runtime:$archVersion"
annotationProcessor "android.arch.persistence.room:compiler:$archVersion"
//Retrofit
compile 'com.squareup.retrofit2:retrofit:2.2.0'
//OkHttp
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okio:okio:1.7.0'
//Gson
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.2.0'
//Glide
compile 'com.github.bumptech.glide:glide:4.0.0-RC0'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile("android.arch.core:core-testing:$archVersion", {
exclude group: 'com.android.support', module: 'support-compat'
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.android.support', module: 'support-core-utils'
})
}
解决方案
您需要在应用级 gradle 文件的底部添加以下代码块。
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.3.1'
}
}
}
}
推荐阅读
- ios - 在 2 个角度之间为 UIBezierPath 弧设置动画
- azure - Azure AD 中用户数据更改的通知
- javascript - 使用 Matter.js 渲染到 DOM 或 React
- firebase - 如何在创建新用户颤动的同时保持当前用户不变
- r - 有没有办法让用户输入附加到spotfire中的表格?
- python - 如何在使用 pandas 或任何 python 模块进行计算时获取单元格中的百分比符号
- flutter - 嵌套水平列表视图
- installation - Dataflow Worker:安装包失败:安装失败要求:退出状态 1
- docker - 如何将 docker 开关传递给 gcloud ai-platform?
- c - 检查旧版 CSP 是否支持“PP_KEYSET_SEC_DESCR”标志