重复条目:com/google/firebase/FirebaseApiNotAvailableException.class

10

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

尝试将Play服务从8.4.0升级到9.2.0,同时升级了GPS类路径。

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:3.0.0'

...

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'

注意,我没有明确地依赖Firebase。

自从升级后,我遇到了以下Gradle构建错误:

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: 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的顶部:

enter image description here

但是我无论如何都找不出原因。


4个回答

22

嗯,罪魁祸首是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'

因此:

输入图像描述

顺便提一下,这个问题促使我深入研究Gradle依赖管理。我写了一篇关于解决常见依赖问题的详细文章


3
我遇到了一个不同的问题,但是这个答案起了作用 :) - SjoerdvGestel
3
我曾经遇到相同的问题,但是当我添加了firebase-core版本10.0.1后,出现了以下错误:com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/api/zze.class。将版本回滚到9.2.1后问题得到解决。感谢您的帖子! - mienaikoe

1
问题在于您在build.gradle文件中同时使用了这两个插件,因此请删除Google Play服务插件,例如:
apply plugin: 'com.google.gms.google-services'

compile 'com.google.android.gms:play-services:11.0.2'

所以先删除一个库,然后再添加。保留HTML标记不解释。
packagingOptions {
    exclude 'META-INF/NOTICE' // It is not include NOTICE file
    exclude 'META-INF/LICENSE' // It is not include LICENSE file
}

0

0
在我的情况下,我正在使用app/build.gradle文件中的这个:
compile 'com.google.android.gms:play-services-location:9.8.0'
compile 'com.google.android.gms:play-services-maps:9.8.0'

当我尝试生成签名的APK时,出现了以下错误:

Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/firebase/FirebaseApiNotAvailableException.class

我通过删除上述提到的两行代码并使用以下代码进行修改:app/build.gradle

compile 'com.google.android.gms:play-services:9.8.0'

当然,“play-services”是完整的捆绑包,而不是优化的方法来实现这一点。最好指定所需的具体服务(参见{{link1:“play-services:9.8.0”是否包括“play-services-location:9.8.0”?}}),但就目前而言,它已经修复了我的错误。


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