Ionic cordova build android gives an error

Hi,

I was working on an ionic project but I’m facing an issue while generating its android apk.
I have built an apk of it many times. And I usually make a backup of my project everytime I finish one specific functionality in the application. Now I added some new functionalities in the app and its started giving an error when I generate the apk. I couldnt manage to resolve it so I took the latest backup of my project, which was generating an apk before, and now I cant generate its apk also.

i have no idea why.

This is what it says in the cmd:

FAILED
35 actionable tasks: 1 executed, 34 up-to-date
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':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 40s
(node:3136) UnhandledPromiseRejectionWarning: Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':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 40s
    at ChildProcess.whenDone (C:\Users\Ahsan\Desktop\ConrodProject\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
(node:3136) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:3136) [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.

These are the details of my environment:

cli packages: (C:\Users\Ahsan\AppData\Roaming\npm\node_modules)

    @ionic/cli-utils  : 1.19.2
    ionic (Ionic CLI) : 3.20.0

global packages:

    cordova (Cordova CLI) : 8.0.0

local packages:

    @ionic/app-scripts : 3.1.9
    Cordova Platforms  : android 6.4.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Node : v8.11.3
    npm  : 5.6.0
    OS   : Windows 10

Environment Variables:

    ANDROID_HOME : not set

Misc:

    backend : pro

What do I need to do here or what am I missing?

Your Cordova tooling seems to be out of date, which might be causing all kinds of problems.
You can read about how to figure out the current Cordova versions and how to update CLI, platforms and plugins here: How to update Cordova CLI, Platforms and Plugins · ionic.zone

Use Android version 6.3.0. It will work for you.

Hi Mohsan,

Thanks for your reply. Yes the apk does build when I use Android version 6.3.0 but it crashes. I have tried it many times before also but this doesnt work.
STILL NEED HELP IN THIS.

Hi Sujan,

I have been trying with new platforms as well but the problem still persists. Can you let me know specifically what needs to be changed?

Thanks.

I pointed it out exactly and posted a link that teaches you how to find out which is the newest version and how you can upgrade to it.