Android依赖项'..'具有不同版本的编译(..)和运行时(..)类路径

时间:2017-11-13 13:59:01

标签: android android-studio firebase gradle android-gradle

我迁移到Android Studio 3和Gradle 4.然后我在build.gradle文件中将compile更改为implementation。但是我得到了错误:

Error:Execution failed for task ':app:preDebugBuild'.
> Android dependency 'com.google.firebase:firebase-core' has different version for the compile (9.0.0) and runtime (11.6.0) classpath. You should manually set the same version via DependencyResolution

当我将implementation更改为api时,错误消失。但这不是解决方案。我有app模块和一个库模块。 App build.gradle只有一个依赖项:

implementation project(':common-lib')

apply plugin: 'com.google.gms.google-services'正确放置在app build.gradle文件的底部(项目在迁移到Gradle 4之前工作)

gradlew应用程序的依赖关系:依赖关系(剪切文本):

编译

debugAndroidTestCompileClasspath - Resolved configuration for compilation for variant: debugAndroidTest
+--- com.google.firebase:firebase-core:9.0.0
|    \--- com.google.firebase:firebase-analytics:9.0.0
|         +--- com.google.android.gms:play-services-basement:9.0.0
|         |    \--- com.android.support:support-v4:23.0.0
|         |         \--- com.android.support:support-annotations:23.0.0
|         +--- com.google.firebase:firebase-common:9.0.0
|         |    +--- com.google.android.gms:play-services-basement:9.0.0 (*)
|         |    \--- com.google.android.gms:play-services-tasks:9.0.0
|         |         \--- com.google.android.gms:play-services-basement:9.0.0 (*)
|         \--- com.google.firebase:firebase-analytics-impl:9.0.0
|              +--- com.google.android.gms:play-services-base:9.0.0
|              |    +--- com.google.android.gms:play-services-basement:9.0.0 (*)
|              |    +--- com.google.firebase:firebase-common:9.0.0 (*)
|              |    \--- com.google.android.gms:play-services-tasks:9.0.0 (*)
|              +--- com.google.android.gms:play-services-basement:9.0.0 (*)
|              +--- com.google.firebase:firebase-iid:9.0.0
|              |    +--- com.google.android.gms:play-services-basement:9.0.0 (*)
|              |    \--- com.google.firebase:firebase-common:9.0.0 (*)
|              \--- com.google.firebase:firebase-common:9.0.0 (*)
\--- project :common-lib
(............)

运行

debugAndroidTestRuntimeClasspath - Resolved configuration for runtime for variant: debugAndroidTest
+--- com.google.firebase:firebase-core:9.0.0 -> 11.6.0
|    \--- com.google.firebase:firebase-analytics:11.6.0
|         +--- com.google.android.gms:play-services-basement:11.6.0
|         |    +--- com.android.support:support-v4:25.2.0 -> 26.1.0
|         |    |    +--- com.android.support:support-compat:26.1.0
|         |    |    |    +--- com.android.support:support-annotations:26.1.0
|         |    |    |    \--- android.arch.lifecycle:runtime:1.0.0
|         |    |    |         +--- android.arch.lifecycle:common:1.0.0
|         |    |    |         \--- android.arch.core:common:1.0.0
|         |    |    +--- com.android.support:support-media-compat:26.1.0
|         |    |    |    +--- com.android.support:support-annotations:26.1.0
|         |    |    |    \--- com.android.support:support-compat:26.1.0 (*)
|         |    |    +--- com.android.support:support-core-utils:26.1.0
|         |    |    |    +--- com.android.support:support-annotations:26.1.0
|         |    |    |    \--- com.android.support:support-compat:26.1.0 (*)
|         |    |    +--- com.android.support:support-core-ui:26.1.0
|         |    |    |    +--- com.android.support:support-annotations:26.1.0
|         |    |    |    \--- com.android.support:support-compat:26.1.0 (*)
|         |    |    \--- com.android.support:support-fragment:26.1.0
|         |    |         +--- com.android.support:support-compat:26.1.0 (*)
|         |    |         +--- com.android.support:support-core-ui:26.1.0 (*)
|         |    |         \--- com.android.support:support-core-utils:26.1.0 (*)
|         |    \--- com.google.android.gms:play-services-basement-license:11.6.0
|         +--- com.google.firebase:firebase-common:11.6.0
|         |    +--- com.google.android.gms:play-services-basement:11.6.0 (*)
|         |    +--- com.google.android.gms:play-services-tasks:11.6.0
|         |    |    +--- com.google.android.gms:play-services-basement:11.6.0 (*)
|         |    |    \--- com.google.android.gms:play-services-tasks-license:11.6.0
|         |    \--- com.google.firebase:firebase-common-license:11.6.0
|         +--- com.google.firebase:firebase-analytics-impl:11.6.0
|         |    +--- com.google.android.gms:play-services-basement:11.6.0 (*)
|         |    +--- com.google.firebase:firebase-iid:11.6.0
|         |    |    +--- com.google.android.gms:play-services-basement:11.6.0 (*)
|         |    |    +--- com.google.firebase:firebase-common:11.6.0 (*)
|         |    |    +--- com.google.android.gms:play-services-tasks:11.6.0 (*)
|         |    |    \--- com.google.firebase:firebase-iid-license:11.6.0
|         |    +--- com.google.firebase:firebase-common:11.6.0 (*)
|         |    +--- com.google.android.gms:play-services-tasks:11.6.0 (*)
|         |    \--- com.google.firebase:firebase-analytics-impl-license:11.6.0
|         \--- com.google.firebase:firebase-analytics-license:11.6.0
\--- project :common-lib
(.............)

编辑:

应用依赖

dependencies {
    implementation project(':common-lib')
}

common-lib依赖

dependencies {
    //android firebase
    implementation "com.google.firebase:firebase-core:$firebase_version"
    implementation "com.google.firebase:firebase-crash:$firebase_version"
    implementation "com.google.firebase:firebase-messaging:$firebase_version"
    implementation "com.google.firebase:firebase-ads:$firebase_version"
    //android support
    implementation "com.android.support:appcompat-v7:$support_version"
    implementation "com.android.support:design:$support_version"
    implementation "com.android.support:cardview-v7:$support_version"
    implementation "com.android.support:percent:$support_version"
    //others
    implementation 'com.google.code.gson:gson:2.8.0'
    implementation 'com.hannesdorfmann:adapterdelegates3:3.0.1'
    implementation 'net.danlew:android.joda:2.9.9'
    implementation 'org.ocpsoft.prettytime:prettytime:4.0.1.Final'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.github.simbiose:Encryption:2.0.1'

    //server
    implementation files('libs/xxx.jar')
    implementation files('libs/yyy.jar')
    implementation files('libs/zzz.jar')

    //tests
    testImplementation 'junit:junit:4.12'

}

版本:

ext {
    firebase_version = '11.6.0'
    support_version = '26.1.0'
}

5 个答案:

答案 0 :(得分:36)

以前,您似乎隐含地依赖于common-lib模块将Firebase SDK导出到您的应用模块。现在你已经改变了"编译"到"实施",您不再导出这些SDK。所以,现在发生的事情是:google-services插件正在将firebase-core的v9.0.0添加到你的应用模块中,因为它不再在应用模块的可见类路径中显示它。

您应该能够通过以正确的版本手动将firebase-core添加到您的应用模块来解决此问题。或者,您可以通过切换到" api"继续将Firebase SDK从库模块导出到您的应用模块。依赖而不是"实现"依赖性。

答案 1 :(得分:5)

这对我有用:

将以下代码添加到您的构建脚本

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 11.6.0"
        }
     }
  }
}

最诚挚的问候,

EDDI

答案 2 :(得分:1)

在顶级gradle文件中更改google-services的版本已为我解决了此问题。似乎旧版本会间接注入firebase-core版本,而更新firebase版本会明显地引起冲突

classpath 'com.google.gms:google-services:4.0.2' // Just updated the version here.

答案 3 :(得分:0)

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

将此代码放入您的项目gradle中

答案 4 :(得分:0)

我将compileSdkVersion和targetSdkVersion升级到28,我也遇到了同样的错误。

我将app.gradle中的所有依赖项版本升级到28.0.0,并将项目.gradle文件中的com.android.tools.build:gradle升级到3.3.2

即类路径'com.android.tools.build:gradle:3.3.2'

此项目成功同步后