Error: Unable to merge dex in deploying to android


#1

Hi all,

I have googled around and tried “ionic cordova clean; ionic cordova build”, but no success.

Ionic info

cli packages: (/Users/xixiao/projects/dublearn/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 : 2.1.4
    Cordova Platforms  : android 7.0.0
    Ionic Framework    : ionic-angular 3.5.3

System:

    Android SDK Tools : 26.1.1
    Node              : v9.9.0
    npm               : 5.6.0
    OS                : macOS High Sierra

Environment Variables:

    ANDROID_HOME : /Users/xixiao/Library/Android/sdk

Misc:

    backend : pro

deploy to android

Running app-scripts build: --platform android --target cordova
[23:36:06]  build dev started ...
[23:36:06]  clean started ...
[23:36:06]  clean finished in 12 ms
[23:36:06]  copy started ...
[23:36:06]  transpile started ...
[23:36:11]  transpile finished in 4.44 s
[23:36:11]  preprocess started ...
[23:36:11]  deeplinks started ...
[23:36:11]  deeplinks finished in 145 ms
[23:36:11]  preprocess finished in 146 ms
[23:36:11]  webpack started ...
[23:36:11]  copy finished in 4.83 s
[23:36:23]  webpack finished in 12.13 s
[23:36:23]  sass started ...
[23:36:24]  sass finished in 1.44 s
[23:36:24]  postprocess started ...
[23:36:24]  removed unused font files
[23:36:24]  postprocess finished in 23 ms
[23:36:24]  lint started ...
[23:36:24]  build dev finished in 18.30 s
> cordova run android
cordova-android-support-gradle-release.before-prepare: No custom version found in config.xml - using plugin default
Android Studio project detected

cordova-android-support-gradle-release.after-prepare: No custom version found in config.xml - using plugin default
ANDROID_HOME=/Users/xixiao/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
studio
Subproject Path: CordovaLib
Subproject Path: app
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
+-----------------------------------------------------------------

| cordova-android-support-gradle-release: 27.+

+-----------------------------------------------------------------

Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.

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_5v5s05ej96ko7wx1m8sd0cmqd.run(/Users/xixiao/projects/dublearn/platforms/android/app/build.gradle:146)

org.xwalk:xwalk_core_library:23+

:CordovaLib:preBuild
 UP-TO-DATE
:CordovaLib:preDebugBuild
 UP-TO-DATE
:CordovaLib:compileDebugAidl
 UP-TO-DATE
:CordovaLib:compileDebugRenderscript
 UP-TO-DATE
:CordovaLib:checkDebugManifest
 UP-TO-DATE
:CordovaLib:generateDebugBuildConfig
 UP-TO-DATE
:CordovaLib:prepareLintJar
UP-TO-DATE

:CordovaLib:generateDebugResValues
 UP-TO-DATE
:CordovaLib:generateDebugResources
 UP-TO-DATE

:CordovaLib:packageDebugResources
UP-TO-DATE
:CordovaLib:platformAttrExtractor
UP-TO-DATE
:CordovaLib:processDebugManifest
 UP-TO-DATE
:CordovaLib:processDebugResources

UP-TO-DATE
:CordovaLib:generateDebugSources
 UP-TO-DATE
:CordovaLib:javaPreCompileDebug

UP-TO-DATE
:CordovaLib:compileDebugJavaWithJavac
 UP-TO-DATE
:CordovaLib:processDebugJavaRes

NO-SOURCE
:CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug
 UP-TO-DATE
:app:cdvCreateAssetManifest

:app:preBuild

:app:preArm64DebugBuild
 UP-TO-DATE
:app:compileArm64DebugAidl
 UP-TO-DATE
:CordovaLib:packageDebugRenderscript NO-SOURCE
:app:compileArm64DebugRenderscript
 UP-TO-DATE
:app:checkArm64DebugManifest UP-TO-DATE
:app:generateArm64DebugBuildConfig UP-TO-DATE
:app:prepareLintJar UP-TO-DATE
:CordovaLib:mergeDebugShaders UP-TO-DATE
:CordovaLib:compileDebugShaders UP-TO-DATE
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets UP-TO-DATE
:app:mergeArm64DebugShaders
 UP-TO-DATE
:app:compileArm64DebugShaders UP-TO-DATE
:app:generateArm64DebugAssets UP-TO-DATE
:app:mergeArm64DebugAssets
 UP-TO-DATE
:app:createXwalkCommandLineFileArm64Debug
:app:generateArm64DebugResValues

:app:generateArm64DebugResources
:app:mergeArm64DebugResources

:app:createArm64DebugCompatibleScreenManifests UP-TO-DATE
:app:processArm64DebugManifest
 UP-TO-DATE
:app:splitsDiscoveryTaskArm64Debug
UP-TO-DATE
:app:processArm64DebugResources
[23:36:31]  lint finished in 6.51 s

:app:generateArm64DebugSources
:app:javaPreCompileArm64Debug
 UP-TO-DATE
:app:compileArm64DebugJavaWithJavac
 UP-TO-DATE
:app:compileArm64DebugNdk NO-SOURCE
:app:compileArm64DebugSources UP-TO-DATE
:app:transformClassesWithStackFramesFixerForArm64Debug
 UP-TO-DATE
:app:transformClassesWithDesugarForArm64Debug
 UP-TO-DATE

:app:transformClassesWithDexBuilderForArm64Debug

UP-TO-DATE
:app:transformDexArchiveWithExternalLibsDexMergerForArm64Debug
 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForArm64Debug'.
> 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 6s

39 actionable tasks: 6 executed, 33 up-to-date
(node:25356) UnhandledPromiseRejectionWarning: Error: /Users/xixiao/projects/dublearn/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForArm64Debug'.
> 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 6s
    at ChildProcess.whenDone (/Users/xixiao/projects/dublearn/platforms/android/cordova/node_modules/cordova-common/src/superspawn.js:169:23)
    at ChildProcess.emit (events.js:180:13)
    at maybeClose (internal/child_process.js:936:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
(node:25356) 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:25356) [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.

#2

package.json

{
    "name": "myApp",
    "version": "0.0.1",
    "author": "Ionic Framework",
    "homepage": "http://ionicframework.com/",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "lint": "ionic-app-scripts lint",
        "lint-fix": "tslint --fix src/**/*.ts -t verbose",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "dependencies": {
        "@angular/common": "4.1.3",
        "@angular/compiler": "4.1.3",
        "@angular/compiler-cli": "4.1.3",
        "@angular/core": "4.1.3",
        "@angular/forms": "4.1.3",
        "@angular/http": "4.1.3",
        "@angular/platform-browser": "4.1.3",
        "@angular/platform-browser-dynamic": "4.1.3",
        "@ionic-native/app-version": "^4.1.0",
        "@ionic-native/camera": "3.10.2",
        "@ionic-native/core": "3.12.1",
        "@ionic-native/facebook": "^3.13.0",
        "@ionic-native/file": "^4.6.0",
        "@ionic-native/file-transfer": "^4.6.0",
        "@ionic-native/google-analytics": "^4.1.0",
        "@ionic-native/google-plus": "^3.13.0",
        "@ionic-native/keyboard": "^3.10.3",
        "@ionic-native/media": "^3.10.3",
        "@ionic-native/screen-orientation": "^4.1.0",
        "@ionic-native/social-sharing": "^3.14.0",
        "@ionic-native/splash-screen": "3.12.1",
        "@ionic-native/status-bar": "3.12.1",
        "@ionic/cloud-angular": "^0.12.0",
        "@ionic/storage": "2.0.1",
        "angular2-logger": "^0.6.0",
        "angularfire2": "^4.0.0-rc.0",
        "cordova-android": "7.0.0",
        "cordova-ios": "^4.4.0",
        "cordova-plugin-app-version": "^0.1.9",
        "cordova-plugin-compat": "^1.2.0",
        "cordova-plugin-console": "^1.0.7",
        "cordova-plugin-crosswalk-webview": "^2.3.0",
        "cordova-plugin-device": "^1.1.6",
        "cordova-plugin-facebook4": "^1.9.1",
        "cordova-plugin-file": "^6.0.1",
        "cordova-plugin-file-transfer": "~1.7.1",
        "cordova-plugin-google-analytics": "^1.8.3",
        "cordova-plugin-googleplus": "^5.1.1",
        "cordova-plugin-media": "^5.0.2",
        "cordova-plugin-screen-orientation": "^2.0.1",
        "cordova-plugin-splashscreen": "^4.0.3",
        "cordova-plugin-statusbar": "^2.2.3",
        "cordova-plugin-whitelist": "^1.3.2",
        "cordova-plugin-wkwebview-engine": "git+https://github.com/ionic-team/cordova-plugin-wkwebview-engine.git",
        "cordova-plugin-x-socialsharing": "^5.1.8",
        "es6-promise-plugin": "^4.1.0",
        "firebase": "^3.9.*",
        "ionic-angular": "3.5.3",
        "ionic-plugin-deploy": "^0.6.7",
        "ionic-plugin-keyboard": "^2.2.1",
        "ionicons": "3.0.0",
        "rxjs": "5.4.0",
        "sw-toolbox": "3.6.0",
        "zone.js": "0.8.12"
    },
    "devDependencies": {
        "@ionic/app-scripts": "^2.0.0",
        "ionic": "3.20.0",
        "tslint-ionic-rules": "0.0.11",
        "typescript": "2.3.3"
    },
    "description": "An Ionic project",
    "cordova": {
        "plugins": {
            "cordova-plugin-console": {},
            "cordova-plugin-device": {},
            "cordova-plugin-splashscreen": {},
            "cordova-plugin-statusbar": {},
            "cordova-plugin-whitelist": {},
            "ionic-plugin-keyboard": {},
            "cordova-plugin-media": {},
            "cordova-plugin-file-transfer": {},
            "cordova-plugin-facebook4": {
                "APP_ID": "1234",
                "APP_NAME": "my App"
            },
            "cordova-plugin-x-socialsharing": {},
            "cordova-plugin-crosswalk-webview": {
                "XWALK_VERSION": "23+",
                "XWALK_LITEVERSION": "xwalk_core_library_canary:17+",
                "XWALK_COMMANDLINE": "--disable-pull-to-refresh-effect",
                "XWALK_MODE": "embedded",
                "XWALK_MULTIPLEAPK": "true"
            },
            "cordova-plugin-googleplus": {
                "REVERSED_CLIENT_ID": "com.googleusercontent.apps.326995514913-kcqip8he7ukjo3l5dt32u46tb4kdmccc"
            },
            "cordova-plugin-google-analytics": {},
            "cordova-plugin-screen-orientation": {},
            "cordova-plugin-wkwebview-engine": {},
            "ionic-plugin-deploy": {},
            "cordova-plugin-app-version": {},
            "cordova-plugin-file": {}
        },
        "platforms": [
            "android",
            "ios"
        ]
    }
}

#3

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: https://ionic.zone/cordova/update

Your Ionic is also pretty outdated, most importantly @ionic/app-scripts.


#4

Thanks! It is indeed a half-year ago project. I will give this article a try and update progress back here.


#5

Hi I’m getting this same error. I just updated everything - no outdated packages.

Ionic:

   ionic (Ionic CLI)  : 4.2.1
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.0.0, ios 4.5.4
   Cordova Plugins       : no whitelisted plugins (19 plugins total)

System:

   Android SDK Tools : 26.1.1 (/Users/willjc/Library/Android/sdk)
   ios-deploy        : 2.0.0
   NodeJS            : v8.11.3 (/usr/local/bin/node)
   npm               : 5.6.0
   OS                : macOS High Sierra
   Xcode             : Xcode 10.1 Build version 10B61

Same error:

  • What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForArm64Debug'.

> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

Any help would be much appreciated! @xixiao did you find the solution for this?


#6

It is a version conflict in the Google Services - Look at platforms/android/project.properties and see is same play services are mentioned with different version