Android Studio 3.0 Execution failed for task: unable to merge dex
Solution 1
For Cordova based project, run cordova clean android
before build again, as @mkimmet suggested.
Solution 2
This error happens when you add an external library which may not be compatible with your compileSdkVersion
.
Be careful when you are adding an external library
.
I spent 2 days on this problem and finally it got solved following these steps.
Make sure all your support libraries are same as
compileSdkVersion
of yourbuild.gradle(Module:app)
in my case it is26
.In your defaultConfig category type multiDexEnabled true. This is the important part.
Go to File | Settings | Build, Execution, Deployment | Instant Run and try to Enable/Disable Instant Run to hot swap... and click okay
Sync
Your project.Lastly, Go to Build | click on Rebuild Project.
Note: Rebuild Project first cleans and then builds the project.
Solution 3
Try to add this in gradle
android {
defaultConfig {
multiDexEnabled true
}
}
Solution 4
Resolution:
Refer to this link: As there are various options to shut the warning off depending on the minSdkVersion, it is set below 20:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
... }
dependencies { compile 'com.android.support:multidex:1.0.3' }
If you have a minSdkVersion greater than 20 in your build.gradle set use the following to shut down the warning:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
}
... }
Update dependencies as follows:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
Again the only difference is the keywords in dependencies:
minSdkVersion below 20: use compile
minSdkVersion above 20: use implementation
- I hope this was helpful, please upvote if it solved your issue, Thank you for your time.
- Also for more info, on why this occurs, please read the first paragraph in the link, it will explain thoroughly why? and what does this warning mean.
Solution 5
Simply try doing a "Build -> Clean Project". That solved the problem for me.
Anguraj
Updated on December 14, 2020Comments
-
Anguraj over 3 years
android studio was getting build error while build execution with following:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex"
My app:build.gradle file:
apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion '26.0.2' defaultConfig { applicationId "com.pdroid.foodieschoice" minSdkVersion 16 targetSdkVersion 25 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.firebaseui:firebase-ui-auth:2.3.0' testCompile 'junit:junit:4.12' } configurations.all { resolutionStrategy { force 'com.android.support:appcompat-v7:26.0.1' force 'com.android.support:support-compat:26.0.1' force 'com.android.support:support-core-ui:26.0.1' force 'com.android.support:support-annotations:26.0.1' force 'com.android.support:recyclerview-v7:26.0.1' } } apply plugin: 'com.google.gms.google-services'
any solutions
Edit: i have done with sample through firebase github site and solved
-
Vineet Jain over 6 yearsHope you have cleared or invalidated your cache and restarted Android Studio ? For me Android Studio 3 seems buggy as compared to the previous versions.
-
68060 over 6 yearsanyone ever fix this? cannot get past it!
-
Ishan Fernando over 6 yearsDid you tried to invalidate cache in android studio? @Anguraj
-
OneCricketeer over 6 yearsNot the only step to enable multidex. Also not needed in newer API levels
-
Sumit Saxena over 6 yearsit is helpful me , Thank you.
-
Niamatullah Bakhshi over 6 yearsglad to hear that. Happy Androiding.
-
Paulo Linhares - Packapps about 6 yearsOnly that worked for me. I did not need to add force = true
-
mkimmet about 6 yearsThanks this worked for me in an Ionic/Cordova project by running cordova clean android while I also had cordova-android-support-gradle-release plugin installed.
-
tonejac about 6 yearsLove it when something simple fixes things!! Thanks!
-
Pradeep Sheoran almost 6 yearsits a dependency put it into gradle
-
pamekar over 5 yearsSomeone please mark this answer right. It solves the problem.
-
Michael Auderer over 5 yearsThis fixed it for me when working with React Native.
-
Niamatullah Bakhshi over 5 years@YajliMaclo great!
-
Mr Special over 4 yearsI changed minSdkVersion, it's enough
-
ssz almost 4 yearsFor me, installing the 'cordova-plugin-androidx' and 'cordova-plugin-androidx-adapter' sovled the problem
-
gautamsinh mori almost 4 yearsThanks, it's the easiest solution for this issue, I spent my 3 days to solve this issue and your answer solves my all problem. Once again thank you my bro!!!
-
Atif over 3 yearsThanks. Helped me on Android Studio 4.1. Saved my day.
-
AndroLogiciels about 2 yearsFor me, just add the line multiDexEnabled=true in defaultConfig