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

Dro*_*ner 99 android build.gradle android-gradle-plugin

将Android Studio从Canary 3更新为Canary 4后,在构建时抛出以下错误.

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

我在整个项目中进行了完整的搜索,并且版本25.1.0没有使用.

APP-的build.gradle

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'
}
Run Code Online (Sandbox Code Playgroud)

库的build.gradle:

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'

}
Run Code Online (Sandbox Code Playgroud)

注意:项目在Canary 3建造得很好

小智 130

在您的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"
        }
     }
  }
}
Run Code Online (Sandbox Code Playgroud)

  • 它对我有用,记得将details.useVersion更改为版本号,如果你只是复制并粘贴它将失败 (8认同)
  • 最好使用rn 0.55,gradle 4.1,构建gradle工具3.0.1 (2认同)
  • 我尝试了此操作,但它仅适用于com.android.support冲突。对于com.google.firebase:firebase-analytics冲突无效。“包含”似乎匹配了太多的程序包。我在[这篇文章](/sf/ask/3108301591/)中使用了更简单的解决方案冲突,并且效果很好。 (2认同)
  • @ user3908686解决了问题,但请解释一下,为什么我们需要添加此内容? (2认同)

Yay*_*ano 80

我有同样的错误,解决了我的问题是什么.在我的库中,而不是使用编译或实现,我使用"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'
}
Run Code Online (Sandbox Code Playgroud)

你可以在这个链接中找到更多关于"api","implementation"的信息/sf/answers/3114536561/

  • 所有的android工作室都建议使用实现..而这个不同寻常的解决方案是有效的.Android工作室的谷歌工程师需要一堂课来向世界学习.多么令人沮丧的工具 (36认同)
  • 它没有解决问题,消息说:"Android依赖'...............'有不同版本的编译" (3认同)
  • 不能解决问题,这是不好的做法 (3认同)

jdo*_*yer 22

您应该能够通过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'
}
Run Code Online (Sandbox Code Playgroud)


小智 16

经过很多时间并得到一位朋友的帮助,这位朋友比我更了解android: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"
        // }
    }
Run Code Online (Sandbox Code Playgroud)

和依赖

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
}
Run Code Online (Sandbox Code Playgroud)

在build.gradle中

allprojects {
   //...
    configurations.all {
        resolutionStrategy.force "com.android.support:support-v4:26.1.0"
    }
Run Code Online (Sandbox Code Playgroud)

在gradle.properties中

android.useDeprecatedNdk=true
android.enableAapt2=false
org.gradle.jvmargs=-Xmx4608M
Run Code Online (Sandbox Code Playgroud)

  • resolutionStrategy.force是唯一对我有用的东西。谢谢! (4认同)

Dac*_*nny 7

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

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

就我而言,必须将解决方案策略封装在一起configurations.all { .. }。我将configurations.all块直接放入app/build.gradle文件中(即configurations.all未嵌套在其他任何文件中)


小智 6

我遇到了同样的错误,我通过将此代码添加到gradle.properties文件来修复它。

android.enableJetifier=true
Run Code Online (Sandbox Code Playgroud)


ALE*_*ANO 5

这对我有用:

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

implementation "com.android.support:appcompat-v7:27.1.0"
Run Code Online (Sandbox Code Playgroud)

或者:27.1.1就我而言