安卓:在jetified-play-services-measurement和jetified-play-services-measurement-impl模块中发现重复的类

42

我正在尝试更新我的一个Android项目的依赖项,但是我遇到了这个奇怪的错误。

罪魁祸首是AdMob的这一行代码(之前我使用的是20.6.0版本):

implementation "com.google.android.gms:play-services-ads:21.0.0"

我遇到了一系列错误:

在jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) 和 jetified-play-services-measurement-impl-20.1.1-runtime (com.google.android.gms:play-services-measurement-impl:20.1.1)模块中都找到了重复的类com.google.android.gms.internal.measurement.zzhx。

在jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) 和 jetified-play-services-measurement-impl-20.1.1-runtime (com.google.android.gms:play-services-measurement-impl:20.1.1)模块中都找到了重复的类com.google.android.gms.internal.measurement.zzna。

在jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) 和 jetified-play-services-measurement-impl-20.1.1-runtime (com.google.android.gms:play-services-measurement-impl:20.1.1)模块中都找到了重复的类com.google.android.gms.internal.measurement.zznb。

在jetified-play-services-measurement-base-20.1.2-runtime (com.google.android.gms:play-services-measurement-base:20.1.2) 和 jetified-play-services-measurement-impl-20.1.1-runtime (com.google.android.gms:play-services-measurement-impl:20.1.1)模块中都找到了重复的类com.google.android.gms.internal.measurement.zznc。

......

以下是我在项目的build.gradle (:app)中使用的所有依赖项:

dependencies {
    implementation "androidx.recyclerview:recyclerview:1.2.1"
    implementation 'androidx.core:core-ktx:1.8.0'
    implementation 'androidx.appcompat:appcompat:1.4.2'
    implementation 'com.google.android.material:material:1.6.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    // Firebase & Crashlytics
    implementation platform('com.google.firebase:firebase-bom:29.2.1')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-crashlytics-ktx'
    //Navigation
    implementation "androidx.navigation:navigation-fragment-ktx:2.4.2"
    implementation "androidx.navigation:navigation-ui-ktx:2.4.2"
    // AdMob
    implementation "com.google.android.gms:play-services-ads:21.0.0"
    // Style
    implementation 'com.intuit.sdp:sdp-android:1.0.5'
    // Play Core
    implementation 'com.google.android.play:core:1.10.3'
    implementation 'com.google.android.play:core-ktx:1.8.1'
    // Billing
    implementation "com.android.billingclient:billing-ktx:5.0.0"
}

以及 build.gradle (My App) 中的依赖项:

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.1.3"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.4.2"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
        classpath "com.google.gms:google-services:4.3.10"
        classpath "com.google.firebase:firebase-crashlytics-gradle:2.8.1"
    }
}

是什么导致了这个错误?如果我将play-services-ads版本回滚到20.6.0,就不会出现任何错误。

感谢您的帮助。

4个回答

109

你还需要更新implementation platform('com.google.firebase:firebase-bom:29.2.1')

 implementation platform('com.google.firebase:firebase-bom:30.1.0')

7
谢谢,这就是解决方案!我之前一直被困扰,因为在Android Studio上这一行没有任何警告。 - Dannis Case
3
我认为,你对一些开发者来说是英雄! - İsa C.
1
干得好,兄弟!谢谢。 - Ben Jima
1
谢谢兄弟,这花了我一天多的时间。 - Ehsan Ullah
好的,谢谢。 - Dhvani023

14

正如错误消息所述,存在一些重复的类(很可能也设置了不兼容的版本),您需要解决/删除这些问题。 对于我的情况,我需要升级Firebase Analytics。这是我找到问题的方法:

我运行了以下命令:

./gradlew -q app:dependencies

通过搜索play-services-measurement可以发现以下代码片段:

|    |    |    +--- com.google.android.gms:play-services-ads:21.2.0
|    |    |    |    +--- androidx.browser:browser:1.4.0
|    |    |    |    |    +--- androidx.collection:collection:1.1.0 -> 1.2.0 (*)
|    |    |    |    |    +--- androidx.concurrent:concurrent-futures:1.0.0 (*)
|    |    |    |    |    +--- androidx.interpolator:interpolator:1.0.0 (*)
|    |    |    |    |    +--- androidx.core:core:1.1.0 -> 1.8.0 (*)
|    |    |    |    |    +--- androidx.annotation:annotation:1.1.0 -> 1.3.0
|    |    |    |    |    \--- com.google.guava:listenablefuture:1.0 -> 9999.0-empty-to-avoid-conflict-with-guava
|    |    |    |    +--- androidx.collection:collection:1.0.0 -> 1.2.0 (*)
|    |    |    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-base:21.2.0
|    |    |    |    |    \--- com.google.android.gms:play-services-basement:18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-identifier:18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-lite:21.2.0
|    |    |    |    |    +--- androidx.work:work-runtime:2.7.0 -> 2.7.1
|    |    |    |    |    |    +--- androidx.annotation:annotation-experimental:1.0.0 -> 1.1.0
|    |    |    |    |    |    +--- com.google.guava:listenablefuture:1.0 -> 9999.0-empty-to-avoid-conflict-with-guava
|    |    |    |    |    |    +--- androidx.lifecycle:lifecycle-livedata:2.1.0 -> 2.5.1 (*)
|    |    |    |    |    |    +--- androidx.startup:startup-runtime:1.0.0 -> 1.1.1 (*)
|    |    |    |    |    |    +--- androidx.core:core:1.6.0 -> 1.8.0 (*)
|    |    |    |    |    |    +--- androidx.room:room-runtime:2.2.5 -> 2.4.2 (*)
|    |    |    |    |    |    +--- androidx.sqlite:sqlite:2.1.0 -> 2.2.0 (*)
|    |    |    |    |    |    +--- androidx.sqlite:sqlite-framework:2.1.0 -> 2.2.0 (*)
|    |    |    |    |    |    +--- androidx.core:core:1.1.0 -> 1.8.0 (*)
|    |    |    |    |    |    \--- androidx.lifecycle:lifecycle-service:2.1.0 -> 2.4.0 (*)
|    |    |    |    |    +--- com.google.android.gms:play-services-ads-base:21.2.0 (*)
|    |    |    |    |    +--- com.google.android.gms:play-services-basement:18.0.0 (*)
|    |    |    |    |    +--- com.google.android.gms:play-services-measurement-sdk-api:20.1.2 (*)


|    +--- com.google.firebase:firebase-analytics:18.0.3
|    |    +--- com.google.android.gms:play-services-measurement:18.0.3
|    |    |    +--- androidx.collection:collection:1.0.0 -> 1.2.0 (*)
|    |    |    +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-ads-identifier:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-base:18.0.3 -> 20.1.2 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-impl:18.0.3
|    |    |    |    +--- androidx.collection:collection:1.0.0 -> 1.2.0 (*)
|    |    |    |    +--- androidx.core:core:1.0.0 -> 1.8.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-ads-identifier:17.0.0 -> 18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    |    +--- com.google.android.gms:play-services-measurement-base:18.0.3 -> 20.1.2 (*)
|    |    |    |    \--- com.google.android.gms:play-services-stats:17.0.0
|    |    |    |         +--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
|    |    |    |         \--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    \--- com.google.android.gms:play-services-stats:17.0.0 (*)
|    |    +--- com.google.android.gms:play-services-measurement-api:18.0.3
|    |    |    +--- com.google.android.gms:play-services-ads-identifier:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-basement:17.0.0 -> 18.0.0 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-base:18.0.3 -> 20.1.2 (*)
|    |    |    +--- com.google.android.gms:play-services-measurement-sdk-api:18.0.3 -> 20.1.2 (*)
|    |    |    +--- com.google.android.gms:play-services-tasks:17.0.0 -> 18.0.1 (*)
|    |    |    +--- com.google.firebase:firebase-common:19.3.0 -> 20.0.0 (*)
|    |    |    +--- com.google.firebase:firebase-components:16.0.0 -> 17.0.0 (*)
|    |    |    +--- com.google.firebase:firebase-installations:16.3.2 -> 17.0.0 (*)
|    |    |    +--- com.google.firebase:firebase-installations-interop:16.0.0 -> 17.0.0 (*)
|    |    |    \--- com.google.firebase:firebase-measurement-connector:18.0.0 (*)
|    |    \--- com.google.android.gms:play-services-measurement-sdk:18.0.3

很显然,我的项目的这两个直接依赖项 com.google.android.gms:play-services-ads:21.2.0com.google.firebase:firebase-analytics:18.0.3 都指定了不同版本的play-services-measurement。如果我们进一步查看play-services-measurement:18.0.3的pom文件:
    <dependency>
      <groupId>com.google.android.gms</groupId>
      <artifactId>play-services-measurement-base</artifactId>
      <version>[18.0.3]</version>
      <scope>compile</scope>
      <type>aar</type>
    </dependency>
    <dependency>
      <groupId>com.google.android.gms</groupId>
      <artifactId>play-services-measurement-impl</artifactId>
      <version>[18.0.3]</version>
      <scope>compile</scope>
      <type>aar</type>
    </dependency>

需要严格使用18.0.3的baseimpl,这使得Gradle无法自行解决问题。

我选择将Firebase Analytics升级到20.1.2,问题得到解决。


谢谢,这是解决神秘的重复类错误的方法!找到冲突的主模块(也就是直接依赖项)并更新其中一个,直到冲突消失。我简直不敢相信构建系统如此脆弱(而且晦涩难懂),但事实就是如此。 - undefined

0

对我来说,移除 implementation 'com.google.firebase:firebase-analytics-ktx' 解决了这个头疼问题。

不确定你是否能够承受移除它,但我这样做了。


-2

我通过更新Flutter版本和在pubspec.yaml中更新包来解决了这个问题。


目前你的回答不够清晰,请编辑并添加更多细节,以帮助其他人理解它如何回答问题。你可以在帮助中心找到有关如何编写好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接