• Register
0 votes
399 views

Problem :

My android studio was getting build error while build execution as following:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex"

7.5k points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

There are many options to shut the warning off depending on the minSdkVersion, it is set below 20:

Update the code as below:

 android {
     defaultConfig {
         ...
         minSdkVersion 15 
         targetSdkVersion 26
         multiDexEnabled true
     }
     ... }
 dependencies {   compile 'com.android.support:multidex:1.0.3' }

If you have the minSdkVersion greater than 20 in your build.gradle set use the following to shut down the warning:

Update the code as below:

  android {
      defaultConfig {
          ...
          minSdkVersion 21 
          targetSdkVersion 26
          multiDexEnabled true
      }
      ... }

Update your dependencies as below:

     dependencies {
implementation 'com.android.support:multidex:1.0.3'
     }

Again the only difference is your keywords in dependencies as below:

If minSdkVersion below 20: use compile

If minSdkVersion above 20: use implementation

 

OR

If above solution is not working for you then try below solution it worked for me and resolved my issue :

Please add below code:

multiDexEnabled true

and also add below code:

packagingOptions {
        exclude 'META-INF/NOTICE' 
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/notice'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license'
        exclude 'META-INF/license.txt'
    }

in your app level Build.gradle file and it will solve your issue

38.6k points
0 votes

Solution:

This error occurs at the time you include an external library which may not be compatible with your compileSdkVersion .

Be sincere at the time you are including an external library.

1. Ensure that all your support libraries are similar as compileSdkVersion of your build.gradle(Module:app) in my case it is 26.

2. In your defaultConfig category type multiDexEnabled true. 

3. Go to File | Settings | Build, Execution, Deployment | Instant Run and attempt 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.

Attempt to include this in gradle

   android {
      defaultConfig {
        multiDexEnabled true
        }
   }

Refer to this link: As there are various options to closed the warning off relying 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' }

In case you have a minSdkVersion greater than 20 in your build.gradle set employ 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: exercise implementation For me, adding

multiDexEnabled true

and

packagingOptions {
        exclude 'META-INF/NOTICE' 
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/notice'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license'
        exclude 'META-INF/license.txt'
    }

I attempted many solutions as mentioned above adding the multiDexEnabled true however none of that worked for me.

Here is the solution which performed for me - copy this code in app\build.gradle file

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support' && requested.name != 'multidex') {
            details.useVersion "${rootProject.ext.supportLibVersion}"
        }
    }
}

Employ multiDexEnabled true as below.

{
 minSdkVersion 17
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}

and

implementation 'com.android.support:multidex:1.0.3'

 

31.7k points
edited by