重复输入:com/google/firebase/FirebaseApiNotAvailableException.class

Vai*_*den 10 android firebase google-play-services android-gradle-plugin react-native

我有一个使用React-Native构建的Android项目,并使用Google Play服务(分析,云消息,广告).我没有在任何地方明确使用Firebase.

尝试从8.4.0 => 9.2.0升级Play服务.还升级了GPS类路径.

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:3.0.0'
Run Code Online (Sandbox Code Playgroud)

...

dependencies {
    compile 'com.google.android.gms:play-services-analytics:9.2.1'
    compile 'com.google.android.gms:play-services-ads:9.2.1'
    compile 'com.google.android.gms:play-services-base:9.2.1'
    compile 'com.google.android.gms:play-services-gcm:9.2.1'
Run Code Online (Sandbox Code Playgroud)

请注意,我并未明确依赖Firebase.

自升级以来,我收到以下Gradle构建错误:

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/google/firebase/FirebaseApiNotAvailableException.class

我知道Firebase捆绑在Google Play服务中(从9.0开始),所以我想其他的东西正在编译并链接到旧版本.所以看看依赖洞察力(gradle -q dependencyInsight --configuration compile --dependency firebase)我注意到firebase-common 9.0.0正在9.2.1之上添加:

在此输入图像描述

但我不能为我的生活找出导致这种情况的原因.

Vai*_*den 23

嗯 - 罪魁祸首是React-Native.

提示是Gradle控制台上显示的这条不起眼的线:

google-services插件无法检测到com.google.android.gms或com.google.firebase的任何版本,将使用默认版本:9.0.0.

修复?通过在build.gradle中添加以下行,强制RN库项目与正确的Firebase版本链接:

compile 'com.google.firebase:firebase-core:9.2.1'
Run Code Online (Sandbox Code Playgroud)

因此:

在此输入图像描述

作为旁注,这个问题让我更深入地了解了gradle依赖管理.我写了一篇关于解决常见依赖问题大量文章.

  • 我有一个不同的问题,但这个答案做了诀窍:)错误:执行失败的任务':app:transformClassesWithJarMergingForDebug'.> com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/google/android/gms/common/api/zza.class (3认同)
  • 我有同样的问题,但当我添加firebase-core版本10.0.1时,我得到:`com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/google/android/gms/common/api/zze.class`将版本回滚到9.2.1修复它.谢谢你的文章! (3认同)