3
votes

I’m getting issue follow while taking android build.

Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug’

Task :CordovaLib:compileDebugShaders UP-TO-DATE Task :CordovaLib:generateDebugAssets UP-TO-DATE Task :CordovaLib:packageDebugAssets UP-TO-DATE Task :app:mergeDebugAssets Task :app:validateSigningDebug UP-TO-DATE Task :app:signingConfigWriterDebug UP-TO-DATE Task :app:transformClassesWithDexBuilderForDebug UP-TO-DATE

Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

FAILURE: Build failed with an exception.

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

    com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

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

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

BUILD FAILED in 22s 35 actionable tasks: 3 executed, 32 up-to-date /Users/panmoh/Documents/mobile-app/platforms/android/gradlew: Command failed with exit code 1 Error output: D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

FAILURE: Build failed with an exception.

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

    com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

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

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

BUILD FAILED in 22s [ERROR] An error occurred while running subprocess cordova.

    cordova build android exited with exit code 1.

    Re-running this command with the --verbose flag may provide more information.

Note : I tried cordova clean android and remove and add android platfoem as well

3

3 Answers

5
votes

To fix this issue for those using Phonegap/Cordova

  • Install the “cordova-plugin-androidx” plugin

    cordova plugin add cordova-plugin-androidx

  • Install “cordova-plugin-androidx-adapter” plugin

    cordova plugin add cordova-plugin-androidx-adapter

  • Add these lines in your gradle.properties :

    android.useAndroidX=true android.enableJetifier=true

After this, make a build: cordova -d build android and check the result

1
votes

solutions is following : make sure the following :

  • Upgrade com.android.tools.build:gradle to v3.2.1 or later.
  • Upgrade compileSdkVersion to 28 or later. . Update your app to use
  • Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.

For Cordova/Ionic project just add the following plugins:

https://github.com/dpa99c/cordova-plugin-androidx https://github.com/dpa99c/cordova-plugin-androidx-adapter Those plugins will fix build error. and everything will work fine :)..

0
votes

The solution accepted here is the true solution. I stuck with this issue for a week and than on last weekend i decided no matter what happens a'll find solution for it.

All credit goes to this person named (ProdoElmit) who answered it here.

Attaching screenshots for above solution to make it easier to follow: gradlew.bat tasks --all

gradlew.bat yourproject:dependencies Here my project name was app

In my case it was FCM which was using androidx and causing this issue. Hope this will help someone to resolve their issue as well. enter image description here