Android 依赖在编译和运行时有不同的版本

标签 android android-gradle-plugin build.gradle

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

Android dependency 'com.android.support:support-support-v4' has different version for the compile (25.2.0) and runtime (26.0.0-beta2) classpath. You should manually set the same version via 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'
}

库构建.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'

}

注意:项目在 Canary 3 中构建良好

最佳答案

在您的构建脚本中使用此代码(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 26.0.0-beta2"
        }
     }
  }
}

关于Android 依赖在编译和运行时有不同的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44653261/

相关文章:

android - 如何在Android Studio中找到gradle插件的所有可用属性和方法?

android - Gradle错误- “Error:arm64-v8a|x86|x86_64|mips|mips64'类型为 'abiType'。”

android - INSTALL_FAILED_INVALID_APK 错误,调试版本代码 1 与 0 不一致

android - 将元数据添加到 xamarin.android 中的 Activity

java - 带有旋转图标的旋转轮

android - Samsung S3 和 S4 (4.2.2+) 的应用程序 UI 问题

java - Gradle 提示它无法将 long 转换为 int,即使该方法需要 long 作为参数

android - 从 1.2.3 升级 android gradle 插件 -> 1.5.0 = 单元测试损坏

android - Gradle 包含一个依赖的依赖

gradle - 无法确定 Gradle 为什么在配置阶段下载 compileClasspath 依赖项