ibm-bluemix-mobile-services/bms-clientsdk-cordova-plugin-push

Unable to compile hello world app with plugin bms-push: duplicate entry

Opened this issue ยท 3 comments

Hi,
when I compile with "cordova build" a new created hello world cordova app with just bms-push plugin I get this error that is drive me crazy:

Execution failed for task ':transformClassesWithJarMergingForDebug'.

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/api/zza.class

This is what I did:
cordova create hello com.hello.app Hello
cordova platform add android
cordova plugin add bms-push
cordova plugin add cordova-plugin-multidex

I follow the documentation for adding things in build.gradle file and i put google-services.json inside the android platform directory.

My packages versions are:

ENVIROMENT
Ubuntu Linux 16.04
Java: OpenJDK 1.8.0_151
Cordova: 7.1.0
npm: 5.6.0
node: v8.9.1

PLATFORM
android: 6.3.0

PLUGINS
bms-core: 2.3.9
bms-push: 3.2.4
cordova-plugin-multidex: 0.1.2

I attach my gradle file and my android sdk configuration

How to make the app compile?
Thanks
Marco

build.gradle.txt

android-sdk-1
android-sdk-2
android-sdk-3

@brennino Hi ,

If you are using the latest version of Push Plugin do the following .
In your platforms/build.gradle file add the following,

  1. Add maven google dependency

buildscript {
  repositories {
      jcenter()
      maven {
          url "https://maven.google.com"
      }
  }

  // Switch the Android Gradle plugin version requirement depending on the
  // installed version of Gradle. This dependency is documented at
  // http://tools.android.com/tech-docs/new-build-system/version-compatibility
  // and https://issues.apache.org/jira/browse/CB-8143
  dependencies {
      classpath 'com.android.tools.build:gradle:3.0.0'
      classpath 'com.google.gms:google-services:3.0.0'
  }
}

// Allow plugins to declare Maven dependencies via build-extras.gradle.
allprojects {
  repositories {
      jcenter()
      maven {
          url "https://maven.google.com"
      }
  }
}
  1. In the Dependencies section , (line 200 )
dependencies {
   compile fileTree(dir: 'libs', include: '*.jar')
   // SUB-PROJECT DEPENDENCIES START
   //debugCompile(project(path: "CordovaLib", configuration: "debug"))
   //releaseCompile(project(path: "CordovaLib", configuration: "release"))
    compile project(':CordovaLib')
   compile 'com.android.support:appcompat-v7:26.1.0'
   compile 'com.google.firebase:firebase-messaging:10.2.6'
   // SUB-PROJECT DEPENDENCIES END
}
apply plugin: 'com.google.gms.google-services'
  1. Open your project in Android studio 3.0 , build and run.

@AnanthaKrish thanks for your fast reply,

Thanks to your reply I has been able to understand the root cause of the problem!
It's the version of firebase-messaging library. My project was using firebase-messaging:9.0.2, changing in my gradle the line:
compile 'com.google.firebase:firebase-messaging:9.0.2'
with
compile 'com.google.firebase:firebase-messaging:10.2.6'
inside build.gradle,
makes my project compile with cordova too.

If other people view this post, isn't possibile to manually edit that part of build.gradle because it's autogenerated from plugins and your changes will be overwritten everytime you build the project. In fact, to be able to change the build.gradle file, you have to:

  • open the file plugin.xml under the plugins/bms-push directory of your project
  • edit the line: <framework src="com.google.firebase:firebase-messaging:9.0.2" /> and change it with <framework src="com.google.firebase:firebase-messaging:10.2.6" />
  • remove android platform with "cordova platform remove android" and recreate it with "cordova platform add android" (this step will destroy all your android platform custom edit)
  • make again the customization you find on the bms-push plugin documentation (put google-services.js, add line under dependences, ecc...)
  • build and run with cordova.

Is it possible to commit the change of the firebase-messaging version on plugin.xml file inside bms-push git repository so it will work just by updating the bms-plugin and without manually change the file?
I don't know if this will break compatibility with previous versions.
I'm curious to understand how this firebase-messaging version is related to my cordova installation and it will be great to understand how to change the firebase-messaging verson in the future for makes things work again.

Thanks again for your support!

Marco

@brennino Wow, thanks a bunch for that one, it really proved a life safer :-)
I have manually modified the bms-push plugin.xml as you describe. Having a hook copying it on "cordova platform add android" could be an option, temporary at least...

I have rumbled about on StackOverflow etc and tried a bunch of things, mainly in build.gradle.

I ended up with a couple of modifications to build.gradle to get the build to succeed, here they are, with source links, if anyone should run into similar stuff:

  1. allprojects section
    // https://stackoverflow.com/questions/45357000/failed-to-resolve-com-android-supportappcompat-v726-0-0
    maven {
    url "https://maven.google.com"
    }

  2. android section

    // https://stackoverflow.com/questions/36707591/duplicate-files-copied-in-apk-meta-inf
    packagingOptions {
    exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml'
    exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties'
    exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.xml'
    exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.properties'
    }
    // https://stackoverflow.com/questions/45301203/no-resource-found-that-matches-the-given-name-attr-androidkeyboardnavigationc
    // compileSdkVersion cdvCompileSdkVersion
    // buildToolsVersion cdvBuildToolsVersion
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

And I am on these bms plugin versions:

bms-core 2.3.8 "BMSCore"
bms-push 3.2.0 "BMSPush"

Cheers
-jo

EDIT: Forgot this:

  1. dependencies section:
    // debugCompile(project(path: "CordovaLib", configuration: "debug"))
    // releaseCompile(project(path: "CordovaLib", configuration: "release"))
    compile project(':CordovaLib')

Thanks to @AnanthaKrish