Help with BUILD FAILED Android Ionic

Hi, i don’t know what happened with build, someone can help me?
Thank you!

global packages:

    @ionic/cli-utils : 1.4.0
    Cordova CLI      : 7.0.1 
    Ionic CLI        : 3.4.0

local packages:

    @ionic/app-scripts              : 1.3.7
    @ionic/cli-plugin-cordova       : 1.4.0
    @ionic/cli-plugin-ionic-angular : 1.3.1
    Cordova Platforms               : android 6.2.3 ios 4.4.0
    Ionic Framework                 : ionic-angular 3.3.0

System:

    Node       : v8.0.0
    OS         : macOS Sierra
    Xcode      : Xcode 8.3.3 Build version 8E3004b 
    ios-deploy : 1.9.1 
    ios-sim    : 5.0.13 
    npm        : 4.6.1 

 :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/internal/zzarh;
        
        * 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: 43.052 secs
        Error:
        /Users/br/Documents/Aplications/app/platforms/android/gradlew:
        Command failed with exit code 1 Error output:
        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/internal/zzarh;
        
        * Try:
        Run with --stacktrace option to get the stack trace. Run with --info or
        --debug option to get more log output.

2 Likes

No I can’t help you as you only posted an image and I can’t copy/paste the error text to search the forum or google for a solution. Please post text and format it so that it is readable.

1 Like

Sorry, I edited the post and pasted the code.
Thank you!

Thanks.

Run the build command again with --verbose at the end. Also try running the same command directly in cordova (leave the ionic off at the beginning but add --info at the end). Also post your ionic cordova plugin list.

Ionic cordova build android --verbose:

[DEBUG] Loading global plugin @ionic/cli-plugin-proxy
[DEBUG] Throwing PLUGIN_NOT_INSTALLED for global @ionic/cli-plugin-proxy
[DEBUG] Loading local plugin @ionic/cli-plugin-cordova
[DEBUG] Loading local plugin @ionic/cli-plugin-ionic-angular

✖ Running command - failed!

[ERROR] Cordova encountered an error.
        You may get more insight by running the Cordova command above directly.
        
[DEBUG] !!! ERROR ENCOUNTERED !!!
[ERROR] An error occurred while running cordova build android (exit code 1):

: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/internal/zzarh;
        
        * 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: 11.179 secs
        Error: /Users/br/Documents/Aplications/app/platforms/android/gradlew: Command failed with
        exit code 1 Error output:
        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/internal/zzarh;
        
        * Try:
        Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

cordova build android --verbose --info:

ANDROID_HOME=/Users/brunoalencar/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
Subproject Path: CordovaLib
Running command: /Users/br/Documents/Aplications/app/platforms/android/gradlew cdvBuildDebug -b /Users/br/Documents/Aplications/app/platforms/android/build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m -Pandroid.useDeprecatedNdk=true
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_3uzczdqa51c43aeglggtapedo.run(/Users/br/Documents/Aplications/app/platforms/android/build.gradle:139)
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).skipWhenEmpty() instead.
: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/internal/zzarh;

* 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: 10.927 secs
Command finished with error code 1: /Users/br/Documents/Aplications/app/platforms/android/gradlew cdvBuildDebug,-b,/Users/br/Documents/Aplications/app/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Dorg.gradle.jvmargs=-Xmx2048m,-Pandroid.useDeprecatedNdk=true
Error: /Users/br/Documents/Aplications/app/platforms/android/gradlew: Command failed with exit code 1 Error output:
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/internal/zzarh;

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

ionic cordova plugin list:

code-push 1.9.0-beta "CodePushAcquisition"
cordova-plugin-admobpro 2.28.3 "AdMob Plugin Pro"
cordova-plugin-apprate 1.3.0 "AppRate"
cordova-plugin-code-push 1.9.4-beta "CodePush"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-dialogs 1.3.3 "Notification"
cordova-plugin-extension 1.5.1 "Cordova Plugin Extension"
cordova-plugin-facebook4 1.9.1 "Facebook Connect"
cordova-plugin-file 4.3.3 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-globalization 1.0.7 "Globalization"
cordova-plugin-google-analytics 1.8.2 "Google Universal Analytics Plugin"
cordova-plugin-googleplus 5.1.1 "Google SignIn"
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"
cordova-plugin-inapppurchase 1.1.0 "In App Purchase"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.1 "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
cordova-sqlite-storage 2.0.4 "Cordova sqlite storage plugin"
ionic-plugin-keyboard 2.2.1 "Keyboard"
onesignal-cordova-plugin 2.1.0 "OneSignal Push Notifications"

Thanks!!

Unfortunately I have no idea what exactly this means and the other commands didn’t give more information or what is causing cordova to crash on it. Something is duplicated, but no idea what and why.

Did the project build before?
Did you add any native Java code (Cordova plugins) recently?

hm, i only install ionic cordova plugin add cordova-plugin-nativestorage and remove, before this i think update Repository Google with Android studio for 54 API, nothing more.

Thanks.

Hi Sujan, just to share the solution, to solve the error I entered the build.gradle inside the platform / and inserted in

defaultConfig {
 multiDexEnabled true
}

After that it worked normally.

Thanks!

6 Likes

What does that do exactly?

I don’t know why, but i think the problem is relational with API 26 Android and cordova.

https://developer.android.com/studio/build/multidex.html

1 Like

I have this same problem.

adding multiDexEnabled true didn’t help.

I am not comfortable editing the build files if this is something Ionic can do. Because I never know if which ones get generated on the fly.

4 Likes

thanks happy new year ,Your solution helped me very much

defaultConfig {
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}

1 Like

thank you @doriantorres84. Your solution works on cordova-android@6.3.0 and cordova-android@6.4.0. So, here make it more detail.

  • open platform/android/build.gradle
  • find android {
  • add this inside
    defaultConfig {
     minSdkVersion 21
     targetSdkVersion 26
     multiDexEnabled true
    }
  • it should looks like this
android {
    defaultConfig {
     minSdkVersion 21
     targetSdkVersion 26
     multiDexEnabled true
    }

    //the rest...
}
7 Likes

Thanks so much for this!

Please help me this is not working for me :confused: Now im getting this.

Thanks! it works for me

Try cordova clean. Saved my day.

15 Likes

Thank you for your reply! “cordova clean” saved my day too!

3 Likes

Thank you @codiqa100051260
Nice Find

Funciono!!! gracias It works thks “cordova clean”