fullstackreact / react-native-firestack

A firestack v3 react-native implementation
MIT License
715 stars 132 forks source link

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

Open THPubs opened 7 years ago

THPubs commented 7 years ago

Hi, I'm trying to add the this package to my app. But it keeps giving the following error :

: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.

I tried to add some packages to exclude group in several packages. But none worked. Here's the ./gradlew clean :app:dependencies result: https://gist.github.com/THPubs/8fe8b4b9c80e3c6cd49541d66887c742

Tried to follow other similar stack overflow question but looks like this package has a lot of dependencies. I was unable to find the conflict.

My build.gradle dependencies:

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'
}
acerbetti commented 7 years ago

I have the same problem

acerbetti commented 7 years ago

Removing compile 'com.google.android.gms:play-services-base:+'

from build.gradle fixed it for me

skizzo commented 7 years ago

Did anybody manage to solve this?

THPubs commented 7 years ago

@acerbetti Doing that only didn't helped in my case :-(

rodrigocurbelo commented 7 years ago

@acerbetti's solution worked for me, I just had to remove this line from node_modules/react-native-firestack/android/build.gradle and it started working again:

compile 'com.google.android.gms:play-services-base:+'

But remove that line from a node_modules package by hand everytime you install the dependencies is not a definitive solution, so I wrote this postinstall npm script:

fs = require('fs');

const FIRESTACK_GRADLE_FILE = 'node_modules/react-native-firestack/android/build.gradle';

fs.readFile(FIRESTACK_GRADLE_FILE, 'utf-8', (err, data) => {
  if (err) {
    throw err;
  }

  let fileLines = data.split('\n');

  lastIndex = (() => {
    for (let i = fileLines.length - 1; i > -1; i--) {
      if (fileLines[i].match('compile \'com.google.android.gms:play-services-base')) {
        return i;
      }
    }
  })();

  delete fileLines[lastIndex];

  fs.writeFile(FIRESTACK_GRADLE_FILE, fileLines.join('\n'), (err, data) => {
    if (err) {
      return console.log(err);
    }

    console.log('Firestack dependence fixed.');
  });
});

Of course, you have to add this line to the package.json in order to ask npm to run it everytime you finish installing a package:

  "scripts": {
    "postinstall": "node fix-firestack.js"
  }

Dummy but it worked.

acerbetti commented 7 years ago

What do we need that package for? Can we just simple do a PR to remove it from the project ?

@rodrigocurbelo thanks for the script, it works for me

studiobrain commented 7 years ago

Removing the dependency in the module did not result in a compiled build. Is there another workaround for this? I cannot even run a successful build.

studiobrain commented 7 years ago

^ follow up from earlier. I build a new react-native app and added only this module with the above: compile 'com.google.android.gms:play-services-base:+' removed and it compiled without error.

bltnico commented 7 years ago

Downgrade to react-native-firestack@2.3.2 with build.gradle :

compile 'com.google.firebase:firebase-database:10.2.0'
compile 'com.google.firebase:firebase-auth:10.2.0'

fixed it for me

cridenour commented 7 years ago

This happens when you have multiple packages requiring different versions of play services. The best way to fix is to make your build.gradle look similar to this

    compile(project(':react-native-firestack')){
        exclude group: 'com.google.android.gms'
        exclude group: "com.google.firebase"
    }

    // your other libraries with similar exclude lines

    compile ("com.google.android.gms:play-services-base:10.0.1") {
        force = true;
    }
    compile ('com.google.firebase:firebase-core:10.0.1') {
        force = true;
    }
    compile ('com.google.firebase:firebase-auth:10.0.1') {
        force = true;
    }
    compile ('com.google.firebase:firebase-analytics:10.0.1') {
        force = true;
    }
    compile ('com.google.firebase:firebase-database:10.0.1') {
        force = true;
    }
    compile ('com.google.firebase:firebase-storage:10.0.1') {
        force = true;
    }
    compile ('com.google.firebase:firebase-messaging:10.0.1') {
        force = true;
    }
ghost commented 7 years ago

In my case the problem was with react-native-maps and the @cridenour solution has worked for me.

Reactive-native-maps has the same solution in its web.

My build.gradle looks like this:

.....
dependencies {
    compile(project(':react-native-firestack')){
           exclude group: 'com.google.android.gms', module: 'play-services-base'
           exclude group: 'com.google.android.gms', module: 'play-services-maps'
       }
    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-maps')){
           exclude group: 'com.google.android.gms', module: 'play-services-base'
           exclude group: 'com.google.android.gms', module: 'play-services-maps'
       }
   compile 'com.google.android.gms:play-services-base:10.0.1'
   compile 'com.google.android.gms:play-services-maps:10.0.1'
}
....
codewithraqib commented 7 years ago

This error is mainly encountered when you have different versions of a particular service. for example:

'com.google.android.gms:play-services-maps:11.0.4'
'compile 'com.google.android.gms:play-services-geo-location:10.0.1'
'compile 'com.google.android.gms:play-services-analytics:13.0.2'

Hope i solved your problem. Thank you!

Sanaebadi97 commented 5 years ago

Just use implementation 'com.google.android.gms:play-services:12.0.1' Hope this solved your problem. Thank you!