execution failed for task appmergedexdebug

execution failed for task appmergedexdebug

* What went wrong: execution failed for task appmergedexdebug

Execution failed for task ‘:app:mergeDexDebug’.

> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade

   > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:

     The number of method references in a .dex file cannot exceed 64K.

     Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

To solve this issue:

    Only thing you need add ‘ multiDexEnabled true ‘ to android/app/build.gradle, android/defaultConfig.
   You can add this line before after versionName.
 
Make sure to include

implementation 'com.android.support:multidex:1.0.3'
 
See this image for details
execution failed for task appmergedexdebug

execution failed for task appmergedexdebug

 
 
 
At last also run ‘gradlew clean’ in android directrly Just to be on safe side
 

What execution failed for task app mergedexdebug?

When you build the android app, It creates .dex file. If you extract a apk file also, you will be able to see this file. What’s happening is that the app cant fit all imported packages into one single .dex file. This is why It is happening. usually this error occurs when you have imported many packages to your your app.

How did we solve this issue?

By enabling multiDexEnabled to true you are giving permission to create more than one .dex file. This way it will create two or more .dex file if required. Anyway, the fix is to add multiDexEnabled true to your app/build.gradle

What if this doesnt work

If it does not work, the best thing is try to other solution that have mentioned on StackOverFlow. Also ensure your minSdkVersion is above 21. If you have solved this issue in any other way make sure to comment it in this post and help each other.

Your App/build.gradle should include these lines in appropriate places

dependencies {
  implementation 'com.android.support:multidex:1.0.3' //enter the latest version
}
android {
    defaultConfig {
        multiDexEnabled true
    }
}