Android 依赖项对于编译和运行时有不同的版本

将 AndroidStudio 从 金丝雀3号更新到 金丝雀4号后,在构建时抛出以下错误。

Android 依赖项“ com.Android.support: support-support-v4”对于编译(25.2.0)和运行时(26.0.0-beta2)类路径有不同的版本。您应该通过 DependencyResolution 手动设置相同的版本。

I ran a complete search throughout the project and the version 25.1.0 is no where used.

应用程序构建,分级

android {
compileSdkVersion 26
buildToolsVersion '26.0.0'




defaultConfig {
applicationId "com.xxx.xxxx"
minSdkVersion 14
targetSdkVersion
versionCode 1
versionName "1.0"
multiDexEnabled true


}




buildTypes {
debug {
debuggable true
}
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}


lintOptions {
abortOnError false
}


}}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation project(':core')
implementation com.google.android.gms:play-services-gcm:9.0.0'


implementation('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
transitive = true
}
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.flurry.android:analytics:7.0.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
implementation 'com.jakewharton:butterknife:8.6.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}

图书馆建设等级:

apply plugin: 'com.android.library'
android {
compileSdkVersion 26
buildToolsVersion '26.0.0'


defaultConfig {
minSdkVersion 14
targetSdkVersion
versionCode 1
versionName "1.0"
}


}


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation files('libs/model.jar')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:percent:26.0.0-beta2'
implementation 'com.android.support:appcompat-v7:26.0.0-beta2'
implementation 'com.android.support:support-core-utils:26.0.0-beta2'


implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.picasso:picasso:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.2.0'
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
implementation 'com.google.code.gson:gson:2.2.4'
implementation 'com.android.support:design:26.0.0-beta2'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.1'


}

注: 项目建设在金丝雀3号

176362 次浏览

通过为您的项目运行正确的 gradle -q dependencies命令,您应该能够准确地看到哪个依赖项将奇数版本作为传递依赖项引入:

Https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies

一旦你追踪到是什么吸引了它,你可以在你的 gradle 文件中添加一个排除项到特定的依赖项中,比如:

implementation("XXXXX") {
exclude group: 'com.android.support', module: 'support-compat'
}

我犯了同样的错误,解决我的问题是。在我的 图书馆中,我没有使用编译或实现,而是使用了“ api”。所以最后我的依赖:

dependencies {
api fileTree(dir: 'libs', include: ['*.jar'])
api files('libs/model.jar')
testApi 'junit:junit:4.12'
api 'com.android.support:percent:26.0.0-beta2'
api 'com.android.support:appcompat-v7:26.0.0-beta2'
api 'com.android.support:support-core-utils:26.0.0-beta2'


api 'com.squareup.retrofit2:retrofit:2.0.2'
api 'com.squareup.picasso:picasso:2.4.0'
api 'com.squareup.retrofit2:converter-gson:2.0.2'
api 'com.squareup.okhttp3:logging-interceptor:3.2.0'
api 'uk.co.chrisjenx:calligraphy:2.2.0'
api 'com.google.code.gson:gson:2.2.4'
api 'com.android.support:design:26.0.0-beta2'
api 'com.github.PhilJay:MPAndroidChart:v3.0.1'
}

你可以在这个链接 https://stackoverflow.com/a/44493379/3479489中找到更多关于“ api”,“实现”的信息

在 buildscript (build.gradle root)中使用以下代码:

subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "version which should be used - in your case 26.0.0-beta2"
}
}
}
}

将硬编码版本替换为 + 例如:

implementation 'com.google.android.gms:play-services-base:+'
implementation 'com.google.android.gms:play-services-maps:+'

我按照埃迪上面提到的解决了这个问题,

 resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.1.0"
}
}

经过漫长的时间,并从一个比我更了解机器人的朋友那里得到帮助: App/build.gradle

android {
compileSdkVersion 27


// org.gradle.caching = true


defaultConfig {
applicationId "com.cryptoviewer"
minSdkVersion 16
targetSdkVersion 23
versionCode 196
versionName "16.83"
// ndk {
//     abiFilters "armeabi-v7a", "x86"
// }
}

和依赖关系

dependencies {
implementation project(':react-native-camera')
//...
implementation "com.android.support:appcompat-v7:26.1.0" // <= YOU CARE ABOUT THIS
implementation "com.facebook.react:react-native:+"  // From node_modules
}

建筑,梯度

allprojects {
//...
configurations.all {
resolutionStrategy.force "com.android.support:support-v4:26.1.0"
}

在 gradle 房地产公司

android.useDeprecatedNdk=true
android.enableAapt2=false
org.gradle.jvmargs=-Xmx4608M

这对我很有效:

在依赖项部分的 app/build.gradle中添加以下代码行:

implementation "com.android.support:appcompat-v7:27.1.0"

对我来说就是 :27.1.1

我注释出 //api 'com.google.android.gms:play-services-ads:15.0.1'它为我工作后,同步

对我来说,答案是把这个也添加到我的 build.gradle文件中:

configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "26.1.0"
}
}
}

In my case, it was nessisary to enclose the resolution strategy in a configurations.all { .. } block. I placed the configurations.all block directly into my app/build.gradle file (ie configurations.all was not nested in anything else)

将我的相互冲突的依赖关系从实现切换到 api 可以解决这个问题。这里有一篇很好的文章解释了这两者的区别。

https://medium.com/mindorks/implementation-vs-api-in-gradle-3-0-494c817a6fa

编辑:

Here's my dependency resolutions as well

 subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex')) {
details.useVersion "28.0.0"
}
if (details.requested.group == 'com.google.android.gms'
&& details.requested.name.contains('play-services-base')) {
details.useVersion "15.0.1"
}
if (details.requested.group == 'com.google.android.gms'
&& details.requested.name.contains('play-services-tasks')) {
details.useVersion "15.0.1"
}
}
}
}

在您的库项目中看到,使 编译 SdkVersionTargetSdkVersion版本达到与您的应用程序相同的水平

android {
compileSdkVersion 28


defaultConfig {
consumerProguardFiles 'proguard-rules.txt'
minSdkVersion 14
targetSdkVersion 28
}
}

也将所有依赖项设置为同一级别

只需在 build.gradle 文件中添加这些行

Force“ com.android.support: support-media-compat: 26.0.0-beta2”

resolutionStrategy.force "com.android.support:support-v4:26.0.0-beta2"

如果有人在2019年遇到这个依赖问题,请将 Android Studio 升级到3.4或更高版本

我通过升级 android/build.gradle 文件中的 gradle 依赖项解决了这个问题: classspath‘ com.android.tools.build: gradle: 3.3.1’(我之前使用的是3.2版本)。

将此代码添加到项目级 build.gradle 文件中。

subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "version which should be used - in your case 28.0.0-beta2"
}
}
}
}

Sample Code :

// Top-level build file where you can add configuration options common to all sub-projects/modules.


buildscript {


repositories {
google()
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath 'io.fabric.tools:gradle:1.31.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
}




subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex') ) {
details.useVersion "28.0.0"
}
}
}
}

在我的例子中,我在两个不同的模块中有两个不同版本的下面的实现,所以我将两个实现都改为版本,即: 6.0.2,并且它工作了。您可能还需要编写依赖项解析来查看接受的答案。

app module

implementation 'com.karumi:dexter:5.0.0'

共用模块

implementation 'com.karumi:dexter:6.0.2'

    configurations.all {
resolutionStrategy.force
//"com.android.support:appcompat-v7:25.3.1"
//here put the library that made the error with the version you want to use
}

将此添加到 allprojects中的 gradle (project)

我也有同样的错误,我通过将这段代码添加到 等级. 属性 文件中来修复它。

android.enableJetifier=true

In my case just adding this property to the gradle.properties file solves the problem.

android.enableJetifier=true

这个工作对我来说,你可以尝试这个解决方案。

android.enableJetifier=true