How do I resolve a failing release build with transform-Dex-Archive-With-Dex-Merger... error?

  • ionic cordova build: works.
  • ionic cordova build --prod: works.
  • ionic cordova build --prod --release: fails with error:
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithDexMergerForRelease'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: 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: org.apache.cordova.BuildHelper

I’ve read all the other questions here on this, nothing seems to work.
Anyone please help me? Thanks.
(please don’t just mark as duplicate!)

Things I’ve tried:

  • reinstalling node
  • reinstalling ionic + cordova
  • re adding the android project (having deleted node_modules + plugins)
  • adding plugin: cordova-plugin-androidx
  • then adding plugin: cordova-plugin-androidx-adapter
  • cordova clean android

Here’s my ionic info output:

Ionic:

   Ionic CLI          : 5.4.1 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.4

Cordova:

   Cordova CLI       : 9.0.0 (cordova-lib@9.0.1)
   Cordova Platforms : android 8.1.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, (and 15 other plugins)

Utility:

   cordova-res : 0.6.0 
   native-run  : 0.2.8 

System:

   ios-deploy : 1.9.2
   ios-sim    : 5.0.8
   NodeJS     : v10.16.3 (/usr/local/bin/node)
   npm        : 6.9.0
   OS         : macOS Mojave
   Xcode      : Xcode 10.3 Build version 10G8

Here’s my project.properties file:

# Project target.
target=android-28
android.library.reference.1=CordovaLib
android.library.reference.2=app
cordova.system.library.1=com.android.support:support-v4:24.1.1+
cordova.system.library.2=com.onesignal:OneSignal:3.11.3
cordova.gradle.include.1=onesignal-cordova-plugin/catsi919243-build-extras-onesignal.gradle
cordova.gradle.include.2=phonegap-plugin-barcodescanner/catsi919243-barcodescanner.gradle
cordova.system.library.3=com.android.support:support-v4:27.+

Here’s my build.gradle file:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        classpath 'com.android.tools.build:gradle:3.3.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }

    //This replaces project.properties w.r.t. build settings
    project.ext {
      defaultBuildToolsVersion="28.0.3" //String
      defaultMinSdkVersion=19 //Integer - Minimum requirement is Android 4.4
      defaultTargetSdkVersion=28 //Integer - We ALWAYS target the latest by default
      defaultCompileSdkVersion=28 //Integer - We ALWAYS compile with the latest by default
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Hey, did you solve this? I’ve got very similar situation here. Please tel me know

Sorry to say no. I was trying to update a V3 Ionic project and all its dependencies to their latest versions, but in the end I rolled everything back and abandoned updating my entire project.

Maintaining a project with separately written Cordova plugins sure is a pain in the ass. I’m done with it.