How to resolve transformDexArchiveWithExternalLibsDexMergerForDebug com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

I'm facing this error while trying to build an app with this component for Android:

[exec-shell] Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForDebug'.
[exec-shell] > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:

The app is practically empty. I just has one form with an instance of this component. I’ve specified:

  • min sdk: 5.0(21)
  • target sdk: 8.1 (27)
  • com.google.android.gms:play-services-vision:11.4.0

I’m using Visualizer Enterprise 8.4.4.
How can I solve this? Thank you,

Hi @Jvmes Hill​

DexArchiveMergerException usually occurs due to duplicate dependency or confliciting dependency

Please make sure you are using same version of com.google.android.gms:play-services-vision which is used in kony

for 8.4.4 it is of version 11.6.0

Use following dependency

com.google.android.gms:play-services-vision:11.6.0

Thanks

Hi @Jvmes Hill​

Are you experiencing the same error, even after changing the play services version to 11.6.0?

Best Regards

Yes, the issue persisted even after specifiying Play Services version to 11.6.0.

I then realised that the log showed:

[exec-shell] WARNING: Configuration \'compile\' is obsolete and has been replaced with \'implementation\' and \'api\'. 394 [exec-shell] It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html

So I tried changing the Gradle entry to:

dependencies { implementation "com.google.android.gms:play-services-vision:11.6.0" }

Then the bit about transformDexArchiveWithExternalLibsDexMergerForDebug went away. But the build still fails with:

com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: ~/ws/temp/JumioDemo2/build/luaandroid/dist/JumioDemo2/build/intermediates/transforms/dexBuilder/debug/0.jar, ... , ~/ws/temp/JumioDemo2/build/luaandroid/dist/JumioDemo2/build/intermediates/transforms/dexBuilder/debug/135.jar

Hi @Jvmes Hill​

We were able to reproduce the issue at our end. After debugging, came to know that build was getting failed due to duplicate entries from dependent libraries.

The fixed component will be published to marketplace shortly. As a workaround, you can try making the following changes to resolve the build issue

#1: Disable these two libraries from the project (In Kony Visualizer, Go to File --> Manage Native Function API(s) --> Android Tab --> From the list of packages)

  • cardview (Android 25.3.1 version)
  • design (Android 25.3.1 version)

#2: Replace the gradle entry with the below snippet:

dependencies

{

implementation "com.google.android.gms:play-services-vision:11.6.0"

implementation "com.android.support:design:28.0.0"

}

Please let us know if you are able to overcome this issue.

Best Regards

@Mvx Wilson​

The solution which i offered to you (In person/offline) will work only with latest plugins

Earlier plugins will have different version of support library version and different google play services version

To know the kony versions build sample app from kony visualizer and please verify the versions from generated build.gradle file (dist/projectfolder/build.gradle)

dependencies

{

implementation "com.google.android.gms:play-services-vision:X"

implementation "com.android.support:design:Y"

}

(X and Y should be replaced)

Thanks

Thank you @Blvke Bond​ for your inputs.

We will update the documentation accordingly to include which library versions to use against the Visualizer version, so that end users will easily make the appropriate version changes while they are consuming the component.

Best Regards,

Vishnu

Remember to use implementation rather than compile for the dependency entries.

Hi @Jvmes Hill​ ,

Just to share the observation. Even if we keep compile, it shouldn't cause any build error. As per the warning mentioned in the console log, compile option is obsolete and will be removed, it's always better to use implementation.

So, will update the documentation with implementation only.

@Blvke Bond​ Here's the full gradle.build file. It was a bit of an indentation mess with lots of white lines, so I've cleaned it up to make it nicer to read but otherwise the content is the same.

I think there's something wrong with it. Notice there's more than one dependencies declaration. On on line 32 and another on line 154.

//Android Gradle build Script:Start import org.apache.tools.ant.taskdefs.condition.Os import java.util.regex.Pattern

buildscript {
repositories {
//Gradle External Repositories
google()
jcenter()
}
dependencies {
//Gradle Build External Dependencies
classpath ‘com.android.tools.build:gradle:3.2.1’
}
}
apply plugin: ‘com.android.application’

def doExtractStringFromManifest(name) {
def manifestFile = file(android.sourceSets.main.manifest.srcFile)
def pattern = Pattern.compile(name + “="(\S+)"”)
def matcher = pattern.matcher(manifestFile.getText())
matcher.find()
return matcher.group(1)
}

configurations.all {
resolutionStrategy {
force “com.android.support:support-v4:28.0.0”
}
}

dependencies {
//Android Project Dependencies :Start
implementation ‘com.android.support:multidex:1.0.0’
implementation ‘com.android.support:recyclerview-v7:28.0.0’
implementation ‘com.android.support:appcompat-v7:28.0.0’
implementation fileTree(dir: ‘libs’, include:[ ‘*.jar’])
//Android Project Dependencies :End
}

fileTree(dir: ‘libs’, include: ‘**/*.aar’).each { File file ->
dependencies.add(“implementation”, [name: file.name.lastIndexOf(‘.’).with { it != -1 ? file.name[0..<it] : file.name }, ext: ‘aar’])
}

android {
//Android build options:Start
compileSdkVersion ‘android-28’
buildToolsVersion ‘28.0.3’
packagingOptions {
//Project packaging options:Start
exclude ‘META-INF/DEPENDENCIES’
exclude ‘META-INF/LICENSE’
exclude ‘META-INF/LICENSE.txt’
exclude ‘META-INF/license.txt’
exclude ‘META-INF/NOTICE’
exclude ‘META-INF/NOTICE.txt’
exclude ‘META-INF/notice.txt’
exclude ‘META-INF/ASL2.0’
exclude ‘MANIFEST.MF’
//Project packaging options:End
}

defaultConfig {
	//Project Default Config:Start
	targetSdkVersion 27
	minSdkVersion 21
	multiDexEnabled true
	sourceSets.main {
		//Project folder mapping:Start
		manifest.srcFile 'AndroidManifest.xml'
		java.srcDirs = ['src']
		resources.srcDirs = ['src']
		aidl.srcDirs = ['src']
		renderscript.srcDirs = ['src']
		res.srcDirs = ['res']
		assets.srcDirs = ['assets']
		jni.srcDirs = [] //disable automatic ndk-build call
		jniLibs.srcDir 'libs' //set .so files location to libs
		//Project folder mapping:End
	}

	dexOptions { 
		//Dexing Options:Start
		javaMaxHeapSize "2048M"
		//Dexing Options:End
		jumboMode true
	}

	renderscriptTargetApi 21
	renderscriptSupportModeEnabled true

	applicationId = doExtractStringFromManifest("package")
	//ABI Filters:Start
	ndk {
		abiFilters  'armeabi-v7a'
	}		
	//ABI Filters:End		
	//Project Default Config:End

	def keystorePropertiesFile = file("$projectDir/../keystore.properties")		
	if(keystorePropertiesFile.exists()){
		def keystoreProperties = new Properties()
		keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
		def keystoreFile = file(keystoreProperties['keyStoreFilePath'])
		if(keystoreFile.exists()){
			signingConfigs {
				release {
					keyAlias keystoreProperties['keyAlias']
					keyPassword keystoreProperties['keyPassword']
					storeFile keystoreFile
					storePassword keystoreProperties['keyStorePassword']
				}
			}
			buildTypes {
				release {
					minifyEnabled false
					signingConfig signingConfigs.release
				}
			}
		}
	}		
}

String apkPaths
applicationVariants.all { variant -&gt;
	variant.outputs.each { output -&gt;
		println variant.buildType.name+"="+output.outputFile
		apkPaths=apkPaths+"\n"+variant.buildType.name+"="+output.outputFile
	}
	new File("outputAPKVariants.properties").text=apkPaths
}
//Android build options:End

}
allprojects {
repositories {
//Gradle Build Depencency Repositories
maven {
url “https://maven.google.com
}
jcenter()
flatDir {
dirs ‘libs’
}
def hasCordovaLibs = file(‘CordovaAssetsLib/libs’).exists()
if (hasCordovaLibs) {
flatDir {
dirs ‘CordovaAssetsLib/libs’
}
}
}
}

//Android Gradle build Script:End
dependencies {
implementation “com.google.android.gms:play-services-vision:11.6.0”
}

question :I think there's something wrong with it. Notice there's more than one dependencies declaration

@Jvmes Hill​

answer : There is no issue in having more than dependencies declaration

Please check if following folder has any support related dependencies (like appcomat,cardview,recyclerview,support-v4) dist/projectfolder/libs folder

if there are any please remove from the libs folder

and add them in gradle entries section with version 28.0.0

Here is some useful information for you

How to resolve dependency conflict issue?

gradle is not printing proper error message in few versions

Please make following changes to dist folder to print the error with proper information

Incase of build failure with below exception

Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: Error while generating the main dex list.

or DexArchieveMerger exception

Below is the debugging procedure:

Step 1: Find which 2 Jars/Dependencies are conflicting by making below changes

These latest tools will print exactly which classes conflict and their sources/origins

Change com.android.tools.build:gradle” version to 3.4.0-alpha09' in dist/projectfolder/build.gradle in generated app

buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.4.0-alpha09' }}

Change distributionUrl in dist/projectfolder/gradle/wrapper/gradle-wrapper.properties to below one

distributionUrl=https://services.gradle.org/distributions/gradle-5.1-milestone-1-all.zip

after making changes please execute following command in dist/projectfolder

command :

gradlew assembleDebug

It will print exact classnames/jars which causing the issue

Step 2: Find from where the conflicting dependencies are pulled using below command

gradlew dependencies

Step 3: Resolving conflicts

Adopt Conflict resolution strategy, if dependency version conflicts is the reason

configurations.all { resolutionStrategy { force "com.android.support:design:28.0.0" } }

Remove if any duplicate jars or classes found in any .aar files and libs

@Blvke Bond​ what's with all the newlines? It looks like you copied and pasted here and this is unreadable. Can you please edit this answer and clean it up?

and...

please use code snippets for code and or logs, markup etc, including JSON and XML file formats.