Failed to merge Dex - Android Studio 3.0

When I upgraded my Android studio to 3.0 in a stable channel and started the project, I started getting the following error.

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

I tried to clean and rebuild the project, but that didn't work. Any help would be appreciated.

Build.gradle project level

 buildscript { repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0' classpath 'com.google.gms:google-services:3.1.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() google() } } task clean(type: Delete) { delete rootProject.buildDir } 

Build.gradle application level

 apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion '26.0.2' defaultConfig { applicationId "com.med.app" minSdkVersion 21 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" resConfigs "auto" multiDexEnabled true } 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' testCompile 'junit:junit:4.12' //appcompat libraries compile 'com.android.support:appcompat-v7:26.1.0' compile 'com.android.support:design:26.1.0' //butterknife compile 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' //picasso compile 'com.squareup.picasso:picasso:2.5.2' //material edittext compile 'com.rengwuxian.materialedittext:library:2.1.4' // Retrofit & OkHttp & and OkHttpInterceptor & gson compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.google.code.gson:gson:2.8.2' compile 'com.squareup.okhttp3:logging-interceptor:3.8.0' // FirebaseUI for Firebase Auth compile 'com.firebaseui:firebase-ui-auth:3.1.0' } apply plugin: 'com.google.gms.google-services' 

I tried all the answers, but I can not solve this error. Please, help.

+42
android android-gradle
Oct 26 '17 at 8:50
source share
21 answers

Add an explicit dependency for play-services-auth along with your firebase-ui-auth dependency:

 // FirebaseUI for Firebase Auth compile 'com.firebaseui:firebase-ui-auth:3.1.0' compile 'com.google.android.gms:play-services-auth:11.4.2' 

This is because firebase-ui-auth has a transitive dependency on play-services-auth and should be used with the corresponding version of play-services-auth . Please see this explanation .

 firebase-ui-auth |--- com.google.firebase:firebase-auth |--- com.google.android.gms:play-services-auth 

Earlier versions of the Gradle build tool did not include transitive dependencies, so now versions can conflict with other versions of play-services .

I explained and answered my question (in case someone wants to know)

When upgrading to Android Studio 3.0 and upgrading the Gradle build tool to 3.0.0, dependency compilation now works differently than in earlier versions.

I recently ran into the same issue. I used these dependencies that worked well until version 2.3.3 of Gradle:

 implementation 'org.apache.httpcomponents:httpmime:4.3.6' implementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1' 

After upgrading to gradle-build-version 3.0.0, I got the same error. Having delved into it, I found that the transitive dependency of httpmime conflicts with the file into which httpclient-android .

Description

Let me explain this in detail. Earlier when using gradle-tool-version 2.3.3 I used httpclient-android to get and use a class called org.apache.http.entity.ContentType.java Transitive dependency extension org.apache.httpcomponents:httpmime:4.3.6 showed that it has org.apache.httpcomponents:httpcore:4.3.6 which is the same package that I wanted to use. But when compiling or synchronizing the assembly, it excluded org.apache.http.entity.ContentType.java so I needed to add this dependency, which includes ContentType.java :

 implementation 'org.apache.httpcomponents:httpclient-android:4.3.5.1' 

After that, everything worked fine.

As soon as I upgraded the version of gradle-build to 3.0.0, everything changed. Now it includes all the transition dependencies. Thus, when compiling with the latest version of Android Studio using gradle-build-tool version 3.0.0, my ContentType.java compiled twice. Once from org.apache.httpcomponents:httpcore:4.3.6 (which is an implicit httpmime transitive dependency) and again from org.apache.httpcomponents:httpclient-android:4.3.5.1 which I used earlier.

To solve this problem, I had to remove the existing org.apache.httpcomponents:httpclient-android:4.3.5.1 since httpmime itself would get the appropriate class needed for my application.

Solution for my situation: use only necessary dependencies and remove httpclient-android

 implementation 'org.apache.httpcomponents:httpmime:4.3.6' 

Please note that this is only for me. You will need to examine your own dependencies and apply the solution accordingly.

+30
Oct 27 '17 at 9:16 on
source share

First of all, I included multidex, as suggested in previous comments.

Then, if the error continues, open the Gradle console (click the "Show console icon" icon to the left of the "Messages" section) and click the link to recompile Debug / Info / Stack options. This will show more detailed error information.

In my case, the error "Unable to merge dex" was caused by duplicate entries in "com.jakewharton.picasso: picasso2-okhttp3-downloader: 1.1.0".

I manually deleted the conflicting library from my project and executed the "Restructuring Project" (forcing to reload the library). This solved the problem.

+14
Oct 26 '17 at 20:19
source share

I had this error:

com.android.builder.dexing.DexArchiveMergerException: Cannot merge dex

and eventually modified my gradle to fix this problem.

Application \ build.gradle

 android { compileSdkVersion 25 //buildToolsVersion '26.0.2' buildToolsVersion '25.0.3'//<< Changed back to old version before my studio 3.0 update defaultConfig { .... 

. \ Build.gradle

 buildscript { repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' //<< Changed back to old version before my studio 3.0 update // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } 

This is not ideal, as it was in the dating, but this is what worked for me, and should get me there until a possible patch is released.

+3
Oct 27 '17 at 14:18
source share

Check the dependencies in your build.gradle (application) if you use 2 (or more) libraries with the same name and different version. For example (in my case):

 implementation files('src/main/libs/support-v4-24.1.1.jar') implementation 'com.android.support:support-v4:27.0.2' 

Remove one, then clean and restore. Also note that dependencies are outside of buildscript .

+3
Jan 31 '18 at 7:49
source share
 android { defaultConfig { multiDexEnabled true } } 

add this line to the file :gradle

+2
Jan 14 '18 at 5:35
source share

I have the same problem. I solved:

 classpath 'com.google.gms:google-services:3.0.0' 

in buildscript-> dependencies

build.gradle

in my file I have:

 buildscript { repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0' classpath 'com.google.gms:google-services:3.0.0' } } 
+1
Oct 26 '17 at 11:17 on
source share

Just change your class path:

classpath 'com.android.tools.build: gradle: 2.3.3'

and sycn gradle.

Hope this helps.

+1
Dec 09 '17 at 21:04 on
source share

Sometimes this error occurs when the same .jar library file is present in the "libs" folder, and at the same time we try to get the source code by adding the line "compile" to the gradle application file.

Any of this, if we remove, we can overcome this error.

Hope this can be helpful.

+1
Feb 09 '18 at 11:17
source share

"all gsm libraries" Thank you, this helped solve my problem, but not only the gsm libraries, but all google libraries should have the same version. I had this dexing error because the version of com.android.support:recyclerview-v7 was different from the version of com.android.support:appcompat-v7

Android studio shows these lines with a red underline in the build.gradle file.

+1
Feb 24 '18 at 19:07
source share

I did the exact one like the hint in the screenshot below, changed 11.0.4 to 11.8.0

 compile 'com.google.android.gms:play-services-base:11.8.0' compile 'com.google.android.gms:play-services:11.8.0' 

works fine

Unable to merge dex

0
Jan 18 '18 at 5:28
source share

This error seems to have many scenarios. In my case, it was build.gradle Java 1.8 in build.gradle (app):

 compileOptions { targetCompatibility 1.8 sourceCompatibility 1.8 } 

I deleted and the error disappeared

0
Jan 29 '18 at 17:21
source share

I changed below from 11.6.0 to 11.8.0 and it worked.

 compile 'com.google.android.gms:play-services-ads:11.6.0' implementation 'com.google.android.gms:play-services-ads:11.8.0' 
0
Feb 07 '18 at 19:13
source share

I encountered the same error in the Firebase user interface database. Even after turning on multiDex, as suggested in other answers, I was still getting an error. Then I found out that it is necessary that the Firebase user interface and the Firebase database have the same corresponding versions as in the Firebase UI GitHub repository.

Firebase UI GitHub

0
Mar 03 '18 at 4:21
source share

Add this to your gradle: implementation of 'com.android.support:multidex:1.0.0'

Clean up the project and then restore. It works

0
Mar 21 '18 at 5:59
source share

It may also be too late, but I think I have an answer too. Based on my recent tests, when compiling the application, make sure that you do not have a jar file and the 'implementation'('compile' for 3.0.1 > gradle) the same package in the same project. In my case, I had an implementation 'org.jsoup:jsoup:1.11.2' and a Jsoup jar in the same project. Newbie mistake, but I found out.

0
Mar 26 '18 at 11:29
source share

For those who are still struggling with this recently and added components. What caused this for me was the addition:

compile 'android.arch.lifecycle: extensions: 1.0.0' annotationProcessor 'android.arch.lifecycle: compiler: 1.0.0'

What fixed this update

compile 'android.arch.lifecycle: extensions: 1.1.1' annotationProcessor 'android.arch.lifecycle: compiler: 1.1.1'

Hope this helps.

0
Mar 29 '18 at 5:03
source share

Adding the following code to build.gradle (application module) works for me

 android { defaultConfig { multiDexEnabled true } } dependencies { androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' implementation 'com.android.support:support-v4:26.1.0' } 
0
Mar 29 '18 at 9:11
source share

I think because different libraries depend on the same child library, but the version is different, so exclude one library dependency, for example:

 api (rootProject.ext.dependencies["bindingRecyclerView"]) { exclude group: 'com.android.support' } 
0
Apr 2 '18 at 8:07
source share

In my case, I had to do three things:

  1. Since I used Firebase, make sure that the Firebase and Google Play services have the same version. Initially, Play services had a lower version. Mostly version 12.0.1 helped

  2. Install this at the application level build.gradle

     android { multiDexEnabled true } 
  3. Again at application level build.gradle add

     compileOptions{ sourceCompatibility 1.8 targetCompatibility 1.8 } 
0
Apr 27 '18 at 6:34
source share

This link solved the problem for me.

First I installed the dependencies in my pubspec.yaml on

 dependencies: flutter: sdk: flutter cloud_firestore: ^0.8.2 

and ran flutter packages get in my IDE terminal.

I also had to change the minimum target version of the SDK:

  1. Open android / app / build.gradle, then find the line labeled minSdkVersion 16.
  2. Change this line to minSdkVersion 21.
  3. Save the file.

Also, I had to open android/app/build.gradle and then add the following line as the last line in the file: apply plugin: 'com.google.gms.google-services'

Then I had to open android/build.gradle , then add a new dependency inside the buildscript tag:

 buildscript { repositories { // ... } dependencies { // ... classpath 'com.google.gms:google-services:3.2.1' // new } } 

After that, my application finally launched on the Android emulator.

The link has a more complete guide if you are stuck.

0
Jul 24 '19 at 16:43
source share

this is my gradle project

android {compileSdkVersion 26 buildToolsVersion "27.0.3"

 defaultConfig { applicationId "net.mobilegts.candyjump" minSdkVersion 14 targetSdkVersion 23 ndk { moduleName "player_shared" } } sourceSets { main { jni.srcDirs = [] } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } 
 defaultConfig { applicationId "net.mobilegts.candyjump" minSdkVersion 14 targetSdkVersion 23 ndk { moduleName "player_shared" } } sourceSets { main { jni.srcDirs = [] } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } 

-one
Apr 14 '18 at 9:07
source share



All Articles