title: What happens during the task transformDexArchiveWithExternalLibsDexMergerForDebug? And when can duplicate classes can cause dex failure?
body: <p>In few cases when I include duplicate classes (with same java package name) as part of different jars then I'm getting this error</p>
  
  <pre><code>&gt; Task :transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
  FAILURE: Build failed with an exception.
  * What went wrong:
  Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForDebug'.
  &gt; java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
  * Try:
  Run with --info or --debug option to get more log output. Run with --scan to get full insights.
  * Exception is:
  org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':transformDexArchiveWithExternalLibsDexMergerForDebug'.
   at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:110)
  </code></pre>
  
  <p>but this is not happening always. Sometimes I'm hitting this hard road and sometimes not. I would like to get clarity on this issue to understand it and avoid it further.</p>
  
  <p>When can I expect this failure? Is that only during when the class files come under same dex something like that? </p>
  
  <p><strong>EDIT</strong>:</p>
  
  <pre><code>Caused by: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
   at com.android.builder.dexing.DxDexArchiveMerger.mergeMultidex(DxDexArchiveMerger.java:266)
   at com.android.builder.dexing.DxDexArchiveMerger.mergeDexArchives(DxDexArchiveMerger.java:133)
   at com.android.build.gradle.internal.transforms.DexMergerTransformCallable.call(DexMergerTransformCallable.java:101)
   at com.android.build.gradle.internal.transforms.ExternalLibsMergerTransform.transform(ExternalLibsMergerTransform.kt:123)
   at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:221)
   at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:217)
   at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
   at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:212)
   at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
   at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
   at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
   at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
   at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:131)
   at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:301)
   at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:293)
   at org.gradle.internal.operations.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:175)
   at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:91)
   at org.gradle.internal.operations.DelegatingBuildOperationExecutor.run(DelegatingBuildOperationExecutor.java:31)
   at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:120)
   at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:99)
   ... 31 more
  Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
  Caused by: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
   at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:72)
   at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
  Caused by: com.android.dex.DexException: Multiple dex files define Lcom/learn/android/candycrush/Origamy$OrigamyCallback;
   at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:660)
   at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:615)
   at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:597)
   at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170)
   at com.android.dx.merge.DexMerger.merge(DexMerger.java:197)
   at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
  </code></pre>