When you build an android project in android studio, you may encounter DexArchiveMergerException unable to merge dex exception. The detailed error message is as below.
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
If you still can not fix this error after struggle for taking some actions such as clean the project, even restart the android studio, you need to look at the error messages carefully.
In my environment, I finally resolve the above error by changing the dependencies library version in the android studio left panel Gradle Scripts —> build.gradle( Module: app) file follows the below steps.
1. How To Fix The DexArchiveMergerException Unable To Merge Dex Exception.
- Double click the Gradle Scripts —> build.gradle( Module: app) file in the android studio left panel to open it.
- Look at each warning message in the right panel build gradle content carefully to know the reason for the error.
- In my build.gradle I found the warning message is that This support library should not use a different version (26) than the compileSdkVersion (27) for the dependency library ‘com.android.support:design:26.1.0’.
- So I change the version to ‘com.android.support:design:27.1.0’.
- After changing the version, click the Sync Now at the top right corner and rebuild the project again, you will find the error has been fixed.
- Conclusion: When you encounter a build error in android studio, you had better look at the build.gradle file content carefully. Especially for the dependencies library with warning messages. Such errors occurred usually because of dependency library version mismatch.