DexArchiveMergerException: Unable to merge dex

I’ve tried implementing unity Admob but then upon implementing the game I get error describing about Dex Archive Merger

CommandInvokationFailure: Gradle build failed. 
C:/Program Files/Java/jdk1.8.0_161\bin\java.exe -classpath "C:\Program Files\Unity\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.2.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx2048m" "assembleDebug"

stderr[

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 43s
]
stdout[
:preBuild UP-TO-DATE
:preDebugBuild
:compileDebugAidl
:compileDebugRenderscript
:checkDebugManifest
:generateDebugBuildConfig
:prepareLintJar
:generateDebugResValues
:generateDebugResources
:mergeDebugResources
:createDebugCompatibleScreenManifests
:processDebugManifest
:splitsDiscoveryTaskDebug
:processDebugResources
:generateDebugSources
:javaPreCompileDebug
:compileDebugJavaWithJavac
:compileDebugNdk NO-SOURCE
:compileDebugSources
:mergeDebugShaders
:compileDebugShaders
:generateDebugAssets
:mergeDebugAssets
:transformClassesWithDexBuilderForDebug
:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
19 actionable tasks: 19 executed
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidJavaTools.RunJava (System.String args, System.String workingdir, System.Action`1 progress, System.String error)
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1 progress)
Rethrow as GradleInvokationException: Gradle build failed
UnityEditor.Android.GradleWrapper.Run (UnityEditor.Android.AndroidJavaTools javaTools, System.String workingdir, System.String task, System.Action`1 progress)
UnityEditor.Android.PostProcessor.Tasks.BuildGradleProject.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

How do I resolve this kind of issue?

5 Answers

5

Looks like if you change Minimum API Level to Android 5.0 it can help with this issue. (it has some other multidex settings). This helped me.

You're my savior !!! Thanks a lot

–

thanks man

–

Thanks! is work for me!

–

This worked for me!! Thanks

–

https://stackoverflow.com/a/72040165/18794205

–

I was able to fix this by going through my plugin folders and finding duplicates.

@k3nz1e What do you mean by duplicates? Since a file name can't be in the same folder more than once, what qualifies as a duplicate? I've been stuck on this for a day

–

Go to build player settings–>Publishing settings and set Release to dropdown Gradle experimental and hit build,worked for me.

I also encountered the same problem. The release build is fine though. Did you find a fix?,I have encountered the same problem. Did you find a solution?

It seems that you cant fix this once this happens to your app the best thing to do is to delete the SDK that causes this error and find a newer version/alternative of that. (also you should've have made a backup before installing an SDK)

–

I am facing the same exact problem from what I read I understood that there are two different versions of the same library but I can't figure out what library or SDK is causing the problem is there a way to do that?

–

In my project firebase and google sigin SDK was causing this conflict I just upgraded minimum android version to 7 instead of 6 and the build worked for me.