Error in ionic cordova run android

#1

Hi,
after I removed and I added again Android platform I have this error while lunch “ionic cordova run android”.
I remove it because when I add Native Streaming plugin my AndroidManifest wont update.
Now Manifest is updated, but I can’t compile application :disappointed_relieved:
I’m very desperate and it was two days I’m trying to solve this.

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

If I execute “cordova run android --verbose” that’s my output:

cordova run android --verbose

No scripts found for hook "before_run".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Discovered plugin "cordova-plugin-streaming-media" in config.xml. Adding it to the project
No scripts found for hook "before_plugin_add".
Calling plugman.fetch on plugin "cordova-plugin-streaming-media@^1.0.2"
Running command: npm install cordova-plugin-streaming-media@^1.0.2
Command finished with error code 0: npm install,cordova-plugin-streaming-media@^1.0.2
Copying plugin "/Users/enfix/Documents/ionic/my-app/node_modules/cordova-plugin-streaming-media" => "/Users/enfix/Documents/ionic/my-app/plugins/com.hutchind.cordova.plugins.streamingmedia"
Calling plugman.install on plugin "/Users/enfix/Documents/ionic/my-app/plugins/com.hutchind.cordova.plugins.streamingmedia" for platform "android
Plugin "com.hutchind.cordova.plugins.streamingmedia" already installed on android.
Calling plugman.install on plugin "/Users/enfix/Documents/ionic/my-app/plugins/com.hutchind.cordova.plugins.streamingmedia" for platform "browser
Plugin "com.hutchind.cordova.plugins.streamingmedia" already installed on browser.
Calling plugman.install on plugin "/Users/enfix/Documents/ionic/my-app/plugins/com.hutchind.cordova.plugins.streamingmedia" for platform "ios
Plugin "com.hutchind.cordova.plugins.streamingmedia" already installed on ios.
Executing script found in plugin cordova-plugin-fcm for hook "after_plugin_add": plugins/cordova-plugin-fcm/scripts/fcm_config_files_process.js
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at /Users/enfix/Documents/ionic/my-app/platforms/android/res/xml/config.xml
Merging project's config.xml into platform-specific android config.xml
Merging and updating files from [www, platforms/android/platform_www] to platforms/android/assets/www
  copy  www/index.html platforms/android/assets/www/index.html (updated file)
Wrote out android application name "MyApp" to /Users/enfix/Documents/ionic/my-app/platforms/android/res/values/strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (0.0.1): 1
Wrote out Android package name "it.enfixweb.MyApp" to /Users/enfix/Documents/ionic/my-app/platforms/android/src/it/enfixweb/MyApp/MainActivity.java
Updating icons at platforms/android/res
Updating splash screens at platforms/android/res
This app does not have additional resource files defined
Prepared android project successfully
Executing script found in hooks directory for hook "after_prepare": hooks/after_prepare/010_add_platform_class.js
Running command: /Users/enfix/Documents/ionic/my-app/hooks/after_prepare/010_add_platform_class.js /Users/enfix/Documents/ionic/my-app
add to body class: platform-android
Command finished with error code 0: /Users/enfix/Documents/ionic/my-app/hooks/after_prepare/010_add_platform_class.js /Users/enfix/Documents/ionic/my-app
Executing script found in plugin cordova-plugin-app-preferences for hook "after_prepare": plugins/cordova-plugin-app-preferences/bin/after_prepare.js
Resolving module name for q => q
Resolving module name for path => path
Resolving module name for elementtree => elementtree
Resolving module name for cordova => cordova
Resolving module name for cordova-lib/src/cordova/util => ../cordova/util
Resolving module name for fs => fs
Resolving module name for q => q
Resolving module name for path => path
Resolving module name for elementtree => elementtree
Resolving module name for cordova => cordova
Resolving module name for cordova-lib/src/cordova/util => ../cordova/util
Resolving module name for fs => fs
Resolving module name for plist => plist
Resolving module name for xcode => xcode
will push strings array {"name":"lang","titles":["English (US)","English (UK)"],"values":["en-us","en-gb"]}
android preferences file was successfully generated
Executing script found in plugin cordova-plugin-fcm for hook "after_prepare": plugins/cordova-plugin-fcm/scripts/fcm_config_files_process.js
Running command: /usr/libexec/java_home 
Command finished with error code 0: /usr/libexec/java_home 
ANDROID_HOME=/Users/enfix/Library/android-sdk-macosx
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
Subproject Path: CordovaLib
Running command: /Users/enfix/Documents/ionic/my-app/platforms/android/gradlew cdvBuildDebug -b /Users/enfix/Documents/ionic/my-app/platforms/android/build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m -Pandroid.useDeprecatedNdk=true
Configuration 'compile' in project ':' is deprecated. Use 'implementation' instead.
google-services plugin could not detect any version for com.google.android.gms or com.google.firebase, default version: 9.0.0 will be used.
please apply google-services plugin at the bottom of the build file.
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_89bcmboiezydbd8ikxd6kwekr.run(/Users/enfix/Documents/ionic/my-app/platforms/android/build.gradle:143)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedFolders(FileCollection)
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
:preBuild UP-TO-DATE
:CordovaLib:preBuild UP-TO-DATE
:CordovaLib:preDebugBuild UP-TO-DATE
:CordovaLib:checkDebugManifest UP-TO-DATE
:CordovaLib:processDebugManifest UP-TO-DATE
:preDebugBuild UP-TO-DATE
:CordovaLib:compileDebugAidl UP-TO-DATE
:compileDebugAidl UP-TO-DATE
:CordovaLib:packageDebugRenderscript NO-SOURCE
:compileDebugRenderscript UP-TO-DATE
:checkDebugManifest UP-TO-DATE
:generateDebugBuildConfig UP-TO-DATE
:prepareLintJar UP-TO-DATE
:generateDebugResValues UP-TO-DATE
:generateDebugResources UP-TO-DATE
:processDebugGoogleServices
Parsing json file: /Users/enfix/Documents/ionic/my-app/platforms/android/google-services.json
:CordovaLib:compileDebugRenderscript UP-TO-DATE
:CordovaLib:generateDebugResValues UP-TO-DATE
:CordovaLib:generateDebugResources UP-TO-DATE
:CordovaLib:packageDebugResources UP-TO-DATE
:mergeDebugResources UP-TO-DATE
:createDebugCompatibleScreenManifests UP-TO-DATE
:processDebugManifest UP-TO-DATE
:splitsDiscoveryTaskDebug UP-TO-DATE
:CordovaLib:platformAttrExtractor UP-TO-DATE
:CordovaLib:processDebugResources UP-TO-DATE
:processDebugResources UP-TO-DATE
:generateDebugSources UP-TO-DATE
:CordovaLib:generateDebugBuildConfig UP-TO-DATE
:CordovaLib:prepareLintJar 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
:javaPreCompileDebug UP-TO-DATE
:compileDebugJavaWithJavac UP-TO-DATE
:compileDebugNdk NO-SOURCE
:compileDebugSources UP-TO-DATE
:mergeDebugShaders UP-TO-DATE
:compileDebugShaders UP-TO-DATE
:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugShaders UP-TO-DATE
:CordovaLib:compileDebugShaders UP-TO-DATE
:CordovaLib:generateDebugAssets UP-TO-DATE
:CordovaLib:mergeDebugAssets UP-TO-DATE
:mergeDebugAssets UP-TO-DATE
:transformClassesWithDexBuilderForDebug UP-TO-DATE
:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED

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 1s
36 actionable tasks: 2 executed, 34 up-to-date
Command finished with error code 1: /Users/enfix/Documents/ionic/my-app/platforms/android/gradlew cdvBuildDebug,-b,/Users/enfix/Documents/ionic/my-app/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Dorg.gradle.jvmargs=-Xmx2048m,-Pandroid.useDeprecatedNdk=true
Error: /Users/enfix/Documents/ionic/my-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 ':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 1s

That’s my Ionic info:

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.9.2
    ionic (Ionic CLI) : 3.9.2

global packages:

    Cordova CLI : 7.0.1 

local packages:

    @ionic/app-scripts : 1.3.7
    Cordova Platforms  : android 6.4.0 browser 4.1.0 ios 4.4.0
    Ionic Framework    : ionic-angular 3.5.3

System:

    ios-deploy : 1.9.2 
    ios-sim    : 5.0.8 
    Node       : v8.4.0
    npm        : 5.3.0 
    OS         : OS X Yosemite
    Xcode      : Xcode 7.2.1 Build version 7C1002 
#2

do you have an emulator on your machine, as cordova run android means that you are running the app through an emulator, if you connect your phone, the you do android run android --device, this will emulate it on the phone itself

#3

I delete all plugin and restored the project. Maybe any bugs…

#4

For me, running “cordova clean” resolved the issue.