Ionic Android Build failed with Multiple dex files define Lcom/google/android/gms/common/api/zza


#1

Hello,

I am working on a professionel project with Ionic 2. I have the presentation with clients coming monday (24/04/2017). Unfortunately from last Friday i am facing a conflict with cordova plugins. The application works well with IOS but build fails with Android. I think the conflict comes with :
–> cordova-plugin-mauron85-background-geolocation “CDVBackgroundGeolocation”
–> cordova-plugin-fcm “FCMPlugin”

At the beggining i had a version conflict, so i changed the version into cordova-plugin-mauron85-background-geolocation with framework src=“com.google.android.gms:play-services-location:9.0.0” . The error was :

Found com.google.android.gms:play-services-location:+, but version 9.0.0 is needed for the google-services plugin.
:processDebugGoogleServices FAILED

After solved the version conflict, now i am facing a new problem. The problem is:

:transformClassesWithDexForDebug
FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:transformClassesWithDexForDebug’.
    com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zza;

And as i have always in my console the following message, i have tried to fix it manually. I tried to apply some solutions that i have found by searches.

The message in console is :

google-services plugin could not detect any version for com.google.android.gms or com.google.firebase, default version: 9.0.0 will be used.
please apply google-services plugin at the bottom of the build file.

The manual fix was adding the following lines in my platforms/android/build.graddle (in correct places):

  • classpath ‘com.google.gms:google-services:3.0.0’ (in classpath dependencies)
  • apply plugin: ‘com.google.gms.google-services’ (at the bottom of the file)

But i got the following error with this modification, so i deleted them :

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘android’.
    Cannot add task ‘:processDebugGoogleServices’ as a task with that name already exists.
  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    Error: cmd: Command failed with exit code 1 Error output:
    FAILURE: Build failed with an exception.

My platforms/android/project.properties :

target=android-24
android.library.reference.1=CordovaLib
cordova.gradle.include.1=cordova-plugin-fcm/myProjectV2-FCMPlugin.gradle
cordova.gradle.include.2=cordova-plugin-mauron85-background-geolocation/myProjectV2-logtofile.gradle
cordova.system.library.3=com.google.android.gms:play-services-location:9.0.0
cordova.system.library.4=com.android.support:support-v4:+

I join my ./gradlew assembleDebug --stacktrace in this link http://pastebin.fr/49855

Hope that i will get some help.
Thanks.


#2

Did you get the solution? I am facing similar issue.


#3

Sorry for the late answer,

After running “ionic run android --device” or “ionic build android”, you need to change all + by a specific version in platform/android/project.properties expect com.android.support:support-v4:+ . In my case, i replaced all + by 9.0.0 and it worked.