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

App*_*evo 23 android gradle firebase android-studio android-gradle-plugin

我移植到Android工作室3和4摇篮然后我改变了compileimplementation我的build.gradle文件.但我得到错误:

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

当我改变implementationapi错误消失.但这不是解决方案.我有app模块和一个库模块.App build.gradle只有一个依赖项:

implementation project(':common-lib')
Run Code Online (Sandbox Code Playgroud)

apply plugin: 'com.google.gms.google-services'正确地放置在该应用的build.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
(............)
Run Code Online (Sandbox Code Playgroud)

运行

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

编辑:

应用程序依赖项

dependencies {
    implementation project(':common-lib')
}
Run Code Online (Sandbox Code Playgroud)

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'

}
Run Code Online (Sandbox Code Playgroud)

版本:

ext {
    firebase_version = '11.6.0'
    support_version = '26.1.0'
}
Run Code Online (Sandbox Code Playgroud)

Dou*_*son 36

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

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


小智 5

这对我有用:

将以下代码添加到您的buildscript中

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

最好的祝福,

EDDI