Getting the error “duplicate entry: com/google/android/gms/internal/zzble.class” when trying to add a package

随声附和 提交于 2019-11-29 05:44:23

Make sure you use the same version in all your google play services libs: For example :

     compile "com.google.firebase:firebase-core:$project.ext.googlePlayServicesVersion"
        compile "com.google.firebase:firebase-auth:$project.ext.googlePlayServicesVersion"
        compile "com.google.firebase:firebase-database:$project.ext.googlePlayServicesVersion"

    project.ext {
        googlePlayServicesVersion = '10.2.0'
}
Purujit Bansal

I got this error today when my dependencies were the following:

compile 'com.google.firebase:firebase-auth:10.2.0'
compile 'com.google.android.gms:play-services-auth:10.2.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.google.firebase:firebase-database:10.0.1'

But it went away when I changed the last dependency to the following:

compile 'com.google.firebase:firebase-auth:10.2.0'
compile 'com.google.android.gms:play-services-auth:10.2.0'
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support:design:25.2.0'
compile 'com.google.firebase:firebase-database:10.2.0'

So make sure you use dependencies with same versions. That is the support libraries should have same version, and same goes for Firebase and Google Play dependencies.

I'm sure you have apply plugin: 'com.google.gms.google-services' somewhere in your build.gradle file, probably on top.

This line has to be after dependencies block - this allows the plugin to determine what version of Play services you are using.

You can refer to https://firebase.google.com/docs/android/setup#add_the_sdk for more information.

In your case it should look like this:

dependencies {
    compile(project(":react-native-firestack"))
    compile project(':react-native-onesignal')
    compile project(':react-native-fbsdk')
    compile project(':react-native-share')
    compile project(':react-native-video')
    compile project(':react-native-uuid-generator')
    compile project(':react-native-udp')
    compile project(':react-native-tcp')
    compile project(':react-native-camera')
    compile project(':react-native-contacts')
    compile project(':react-native-linear-gradient')
    compile project(':react-native-vector-icons')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile project(':react-native-image-picker')
    compile(project(":react-native-google-signin")){
    exclude group: "com.google.android.gms" // very important
    }
    compile 'com.google.android.gms:play-services-auth:10.2.0'
    compile 'com.google.firebase:firebase-crash:10.0.1'
}

// after dependencies block
apply plugin: 'com.google.gms.google-services'

I'm not sure if this is the best fix, but I can get past the problem by going into /node_modules/react-native-firestack/android/build.gradle and replacing all of the 10.0.1 with 10.2.0, and then making sure I use 10.2.0 everywhere in my own android/build.gradle.

Just add following in your build.gradle

    android {
            configurations {
            all*.exclude module: 'play-services-awareness'
            }
    }

Add this to your build.gradle and run gradle findDuplicates

task findDuplicates {
    doLast {
        def findMe = 'com/google/android/gms/internal/zzble.class'
        configurations.compile.asFileTree.matching {
            include '**/*.jar'
        }.files.each { File jarFile ->
            zipTree(jarFile).visit { FileVisitDetails fvd ->
                if (fvd.path == findMe) {
                    println "Found $findMe in $jarFile.name"
                }
            }
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!