Ionic android build error with Admob

I had created my IONIC 2 App and it was working fine but recently we decided to implement ADMOB in our App and I am now stuck with the build issues.

Here is what I did already:

cordova plugin add cordova-plugin-admob-free --save
npm install @ionic-native/admob-free --save

Above plugin did not install for android and asked to upgrade android 6.3.0 or above.

cordova platform update android@6.3.0
cordova plugin add cordova-plugin-admob-free --save
npm install @ionic-native/admob-free --save

After this when I was trying to run ionic cordova build android it was failing issue with Android Platform 26.

I installed sdkmanager "platform-tools" "platforms;android-26"

Now after all this, I was trying to build my project for android and again Multiple dex files issue.

When researching I came to know about this: (android-6.3.0 don’t need cordova-plugin-compat)

https://cordova.apache.org/news/2017/11/10/plugins-release.html

Uninstalled and reinstalled my these plugins:-

cordova plugin add cordova-plugin-device@latest --save
cordova plugin add cordova-plugin-file@latest --save
cordova plugin add cordova-plugin-file-transfer@latest --save
cordova plugin add cordova-plugin-inappbrowser@latest --save
cordova plugin add cordova-plugin-splashscreen@latest --save
cordova plugin add cordova-plugin-statusbar@latest --save
cordova plugin add cordova-plugin-whitelist@latest --save
At the end I am still struggling with the build issue.

Below is the complete out of my build android command.

D:\IONIC\Prod>cordova build android
Running command: "C:\Program Files\nodejs\node.exe" "D:\IONIC\Prod\hooks\after_prepare\010_add_platform_class.j
s" "D:\IONIC\Prod"
add to body class: platform-android
ANDROID_HOME=C:\Users\sannys\AppData\Local\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_91
Subproject Path: CordovaLib
null
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
        at build_5njkbgqufn374rs8tc91txqik.run(D:\IONIC\Prod\platforms\android\build.gradle:143)
org.xwalk:xwalk_core_library:22+
The JavaCompile.setDependencyCacheDir() method has been deprecated and is scheduled to be removed in Gradle 4.0.
Incremental java compilation is an incubating feature.
The TaskInputs.source(Object) method has been deprecated and is scheduled to be removed in Gradle 4.0. Please use TaskInputs.file(Object).skipWhenEmpt
y() instead.
:preBuild UP-TO-DATE
:preArmv7DebugBuild UP-TO-DATE
:checkArmv7DebugManifest
:preArmv7ReleaseBuild UP-TO-DATE
:preX86DebugBuild UP-TO-DATE
:preX86ReleaseBuild UP-TO-DATE
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preDebugBuild UP-TO-DATE
:CordovaLib:checkDebugManifest
:CordovaLib:prepareDebugDependencies
:CordovaLib:compileDebugAidl UP-TO-DATE
:CordovaLib:compileDebugNdk UP-TO-DATE
:CordovaLib:compileLint UP-TO-DATE
:CordovaLib:copyDebugLint UP-TO-DATE
:CordovaLib:mergeDebugShaders UP-TO-DATE
:CordovaLib:compileDebugShaders UP-TO-DATE
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugProguardFiles UP-TO-DATE
:CordovaLib:packageDebugRenderscript UP-TO-DATE
:CordovaLib:compileDebugRenderscript UP-TO-DATE
:CordovaLib:generateDebugResValues UP-TO-DATE
:CordovaLib:generateDebugResources UP-TO-DATE
:CordovaLib:packageDebugResources UP-TO-DATE
:CordovaLib:processDebugManifest UP-TO-DATE
:CordovaLib:generateDebugBuildConfig UP-TO-DATE
:CordovaLib:processDebugResources UP-TO-DATE
:CordovaLib:generateDebugSources UP-TO-DATE
:CordovaLib:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:CordovaLib:compileDebugJavaWithJavac UP-TO-DATE
:CordovaLib:processDebugJavaRes UP-TO-DATE
:CordovaLib:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:CordovaLib:transformClassesAndResourcesWithSyncLibJarsForDebug UP-TO-DATE
:CordovaLib:mergeDebugJniLibFolders UP-TO-DATE
:CordovaLib:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:CordovaLib:transformNative_libsWithSyncJniLibsForDebug UP-TO-DATE
:CordovaLib:bundleDebug UP-TO-DATE
:CordovaLib:preReleaseBuild UP-TO-DATE
:CordovaLib:checkReleaseManifest
:CordovaLib:prepareReleaseDependencies
:CordovaLib:compileReleaseAidl UP-TO-DATE
:CordovaLib:compileReleaseNdk UP-TO-DATE
:CordovaLib:copyReleaseLint UP-TO-DATE
:CordovaLib:mergeReleaseShaders UP-TO-DATE
:CordovaLib:compileReleaseShaders UP-TO-DATE
:CordovaLib:generateReleaseAssets UP-TO-DATE
:CordovaLib:mergeReleaseAssets UP-TO-DATE
:CordovaLib:mergeReleaseProguardFiles UP-TO-DATE
:CordovaLib:packageReleaseRenderscript UP-TO-DATE
:CordovaLib:compileReleaseRenderscript UP-TO-DATE
:CordovaLib:generateReleaseResValues UP-TO-DATE
:CordovaLib:generateReleaseResources UP-TO-DATE
:CordovaLib:packageReleaseResources UP-TO-DATE
:CordovaLib:processReleaseManifest UP-TO-DATE
:CordovaLib:generateReleaseBuildConfig UP-TO-DATE
:CordovaLib:processReleaseResources UP-TO-DATE
:CordovaLib:generateReleaseSources UP-TO-DATE
:CordovaLib:incrementalReleaseJavaCompilationSafeguard UP-TO-DATE
:CordovaLib:compileReleaseJavaWithJavac UP-TO-DATE
:CordovaLib:processReleaseJavaRes UP-TO-DATE
:CordovaLib:transformResourcesWithMergeJavaResForRelease UP-TO-DATE
:CordovaLib:transformClassesAndResourcesWithSyncLibJarsForRelease UP-TO-DATE
:CordovaLib:mergeReleaseJniLibFolders UP-TO-DATE
:CordovaLib:transformNative_libsWithMergeJniLibsForRelease UP-TO-DATE
:CordovaLib:transformNative_libsWithSyncJniLibsForRelease UP-TO-DATE
:CordovaLib:bundleRelease UP-TO-DATE
:prepareAndroidArchLifecycleRuntime103Library UP-TO-DATE
:prepareComAndroidSupportMultidex101Library UP-TO-DATE
:prepareComAndroidSupportSupportCompat2702Library UP-TO-DATE
:prepareComAndroidSupportSupportCoreUi2702Library UP-TO-DATE
:prepareComAndroidSupportSupportCoreUtils2702Library UP-TO-DATE
:prepareComAndroidSupportSupportFragment2702Library UP-TO-DATE
:prepareComAndroidSupportSupportMediaCompat2702Library UP-TO-DATE
:prepareComAndroidSupportSupportV132340Library UP-TO-DATE
:prepareComAndroidSupportSupportV42702Library UP-TO-DATE
:prepareComFacebookAndroidFacebookAndroidSdk482Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesAds1104Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesAdsLite1104Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesAnalytics1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesAnalyticsImplLicense1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesAnalyticsLicense1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesBase1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesBaseLicense1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesBasement1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesBasementLicense1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesClearcut1104Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesGass1104Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesGcm1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesGcmLicense1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesIid1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesIidLicense1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesSafetynet1104Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesTagmanagerV4Impl1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesTagmanagerV4ImplLicense1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesTasks1180Library UP-TO-DATE
:prepareComGoogleAndroidGmsPlayServicesTasksLicense1180Library UP-TO-DATE
:prepareMeLeolinShortcutBadger1114Library UP-TO-DATE
:prepareOrgApacheCordovaCordovaLib630DebugLibrary UP-TO-DATE
:prepareOrgXwalkXwalk_core_library22525614Library UP-TO-DATE
:prepareArmv7DebugDependencies
:compileArmv7DebugAidl UP-TO-DATE
:compileArmv7DebugRenderscript UP-TO-DATE
:generateArmv7DebugBuildConfig UP-TO-DATE
:mergeArmv7DebugShaders UP-TO-DATE
:compileArmv7DebugShaders UP-TO-DATE
:generateArmv7DebugAssets UP-TO-DATE
:mergeArmv7DebugAssets
:createXwalkCommandLineFileArmv7Debug
:generateArmv7DebugResValues UP-TO-DATE
:generateArmv7DebugResources UP-TO-DATE
:mergeArmv7DebugResources UP-TO-DATE
:processArmv7DebugManifest UP-TO-DATE
:processArmv7DebugResources UP-TO-DATE
:generateArmv7DebugSources UP-TO-DATE
:incrementalArmv7DebugJavaCompilationSafeguard UP-TO-DATE
:compileArmv7DebugJavaWithJavac UP-TO-DATE
:compileArmv7DebugNdk UP-TO-DATE
:compileArmv7DebugSources UP-TO-DATE
:transformClassesWithDexForArmv7Debug FAILED

BUILD FAILED

Total time: 1 mins 10.541 secs

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithDexForArmv7Debug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.an
droid.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzev;

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
(node:7816) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: Command failed with exit code 1 Error output:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithDexForArmv7Debug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.an
droid.dex.DexException: Multiple dex files define Lcom/google/android/gms/internal/zzev;

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