Android build fails after adding AdMob Free plugin

My App was building fine until I added the “AdMob Free” native plugin. iOS build still forks but for ionic cordova build android it fails with the following:

FAILED

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':transformClassesWithJarMergingForRelease'.
> 
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzau.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: 12.786 secs

Error: /Users/Daniel/Code/baseball/baseball_app/platforms/android/gradlew: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

FAILURE: Build failed with an exception.

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

I already tried removing and re-adding the android platform. Once I remove the plugin everything builds fine again.

I have installed the following plugins:

cordova-admob-sdk 0.13.1 "AdMob SDK"
cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-admob-free 0.13.0 "Cordova AdMob Plugin"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-dialogs 1.3.3 "Notification"
cordova-plugin-email-composer 0.8.7 "EmailComposer"
cordova-plugin-firebase 0.1.24 "Google Firebase Plugin"
cordova-plugin-globalization 1.0.8 "Globalization"
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"
cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.2 "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-promise-polyfill 0.0.2 "cordova-promise-polyfill"
cordova-sqlite-storage 2.0.4 "Cordova sqlite storage plugin"
ionic-plugin-keyboard 2.2.1 "Keyboard"
me.tonny.cordova.plugins.multidex 0.1.0 "Cordova Multi Dex"
onesignal-cordova-plugin 2.2.0 "OneSignal Push Notifications"
uk.co.workingedge.phonegap.plugin.launchnavigator 4.0.4 "Launch Navigator"

My setup is the following:

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.0
    ionic (Ionic CLI) : 3.19.0

global packages:

    cordova (Cordova CLI) : 7.1.0 

local packages:

    @ionic/app-scripts : 1.3.8
    Cordova Platforms  : android 6.3.0 ios 4.4.0
    Ionic Framework    : ionic-angular 3.4.2

System:

    Android SDK Tools : 26.0.2
    ios-deploy        : 1.9.2 
    Node              : v7.7.3
    npm               : 4.4.4 
    OS                : macOS High Sierra
    Xcode             : Xcode 9.2 Build version 9C40b 

Environment Variables:

    ANDROID_HOME : /Users/Daniel/Library/Android/sdk/

Misc:

    backend : pro

Any ideas what the problem might be? Thank you in advance!

1 Like

My guess is that another plugin defines the same classes somehow. Remove them one by onw and see which one fixes the problem.

You could also try upgrading to cordova-android 6.4.0.

I was getting the same error when using both phonegap-push-plugin and admob-free plugin in my app.

There was an dependency collision issue between these two plugins and I solved it by changing my build.gradle (platforms->android) dependencies to use the same version of com.google.whateverfollows.

This is how the relevant dependencies look now

dependencies {
... other stuff ...
       compile "com.google.firebase:firebase-messaging:11.2.0"
       compile "com.google.android.gms:play-services-base:11.2.0"
       compile "com.google.android.gms:play-services-ads:11.2.0"
... other stuff ... 
}

But before each one of these was using different version, for example

dependencies {
... other stuff ...
       compile "com.google.firebase:firebase-messaging:9.7.0"
       compile "com.google.android.gms:play-services-base:10.0.4"
       compile "com.google.android.gms:play-services-ads:11.1.0"
... other stuff ... 
}

so you do you have to change that manually?