3
votes

I am having trouble in building my ionic 3 app. Every time I try to build the android app it gives the following error.

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

  • Try: 37 actionable tasks: 10 executed, 27 up-to-date Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  • Get more help at https://help.gradle.org

BUILD FAILED in 35s (node:5924) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: cmd: 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 unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Picked up _JAVA_OPTIONS: -Xmx512M

Picked up _JAVA_OPTIONS: -Xmx512M

Picked up _JAVA_OPTIONS: -Xmx512M

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

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

  • Get more help at https://help.gradle.org

BUILD FAILED in 35s Picked up _JAVA_OPTIONS: -Xmx512M (node:5924) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Can anyone help me with the issue?

4
Try running "cordova clean"karl
@karl tried it already, still same errorShreyas Pednekar
Anyone got a solution to this? I've tried reinstalling nodejs, then cordova and ionic from scratch, then re-adding the android platform. But then i get this error and can't build at all.Dave

4 Answers

4
votes

cordova clean android should fix your problem.

3
votes

I solved it by removing platform and adding it again:

ionic cordova platform rm android
ionic cordova platform rm ios

ionic cordova platform add android
ionic cordova platform add ios
2
votes

If the cordova clean command does not solve this problem for you, it might be related to the new implementation of AndroidX in some of your libraries.

In my case it was cordova-plugin-firebase-analytics

Follow these steps:

0 / Remove your android platform

cordova platform rm android

1 / Remove all plugins related to support / gradle / firebase versions control (Optional -- I didn't need to remove any plugins. So if you are not sure about how to do this, just skip this step)

2 / Add the AndroidX plugins from @dpa99c :

# add plugin to enable AndroidX in the project
cordova plugin add cordova-plugin-androidx

# add plugin to patch existing plugin source that uses the Android Support Library to use AndroidX
cordova plugin add cordova-plugin-androidx-adapter

3 / Add your android platform

cordova platform add android

Thanks to @MathieuNa : https://forum.ionicframework.com/t/d8-program-type-already-present/166812/4?u=carlosglegaspi

0
votes

Delete this folder: "../app/build"