在尝试添加包时出现错误“重复条目:com / google / android / gms / internal / zzble.class”

时间:2017-03-03 13:24:52

标签: android gradle react-native build.gradle

我正在尝试将react-native-firestack包添加到我的应用中。但它一直给出以下错误:

:app:mergeDebugResources UP-TO-DATE
:app:recordFilesBeforeBundleCommandDebug
:app:bundleDebugJsAndAssets SKIPPED
:app:generateBundledResourcesHashDebug
4f53cda18c2baa0c0354bb5f9a3ecbe5ed12ab4d8e11ba873c2f11161202b945
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:transformClassesWithJarMergingForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzble.class

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.498 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment.
Go to https://facebook.github.io/react-native/docs/getting-started.html
and check the Android tab for setup instructions.

我尝试在几个包中向exclude group添加一些包。但都没有效果。以下是./gradlew clean :app:dependencies结果:https://gist.github.com/THPubs/8fe8b4b9c80e3c6cd49541d66887c742

试图遵循其他类似的堆栈溢出问题,但看起来这个包有很多依赖。我无法找到冲突。

我的build.gradle个依赖关系:

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'
}

6 个答案:

答案 0 :(得分:14)

确保在所有Google Play服务库中使用相同的版本: 例如:

     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'
}

答案 1 :(得分:4)

今天我的依赖关系是以下时出现此错误:

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'

但是当我将最后一个依赖项更改为以下内容时它就消失了:

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'

因此,请确保使用相同版本的依赖项。这就是支持库应该具有相同的版本,同样适用于Firebase和Google Play依赖项。

答案 2 :(得分:0)

将其添加到build.gradle并运行conversation_id = parseInt(document.URL.match(new RegExp("conversations/"+ "(.*)"))[1]) # gets the conversation id from the url of the page App.conversation = App.cable.subscriptions.create { channel: "ConversationChannel", conversation_id: conversation_id }, connected: -> # Called when the subscription is ready for use on the server disconnected: -> # Called when the subscription has been terminated by the server received: (data) -> $('#messages').append data['message'] speak: (message) -> @perform 'speak', message: message

gradle findDuplicates

答案 3 :(得分:0)

我确定你的build.gradle文件中有apply plugin: 'com.google.gms.google-services',可能在顶部。

此行必须在依赖项阻止之后 - 这允许插件确定您正在使用的Play服务版本。

您可以参考https://firebase.google.com/docs/android/setup#add_the_sdk了解更多信息。

在你的情况下它应该是这样的:

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'

答案 4 :(得分:0)

我不确定这是否是最佳解决方案,但我可以通过进入/node_modules/react-native-firestack/android/build.gradle并将所有10.0.1替换为所有问题来解决问题。 10.2.0,然后确保我在自己的android / build.gradle中使用10.2.0。

答案 5 :(得分:0)

只需在build.gradle

中添加以下内容即可
    android {
            configurations {
            all*.exclude module: 'play-services-awareness'
            }
    }