Unable to Merge Dex - Android Studio 3.0

First of all I enabled multidex as suggested in previous comments.

Then, if the error continues, open the Gradle Console (click on "Show Console Output" icon at left of "Messages" section) and click on the link to recompile with Debug/Info/Stack options. This will show further details about the error.

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 removed the conflicting library from my project and executed the "Rebuild Project" (forcing to reload the library). This solved the issue.


I had this error:

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

and ended up changing back my gradle in order to fix this issue.

app\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
}

It's not ideal as it's back dating, but it's something which worked for me and should get me there until a possible patch is released.


Add an explicit dependency to 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 to play-services-auth and must 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 play-services versions.

My Issue Explained and Answered (In case anyone wants to know)

When you upgrade to Android Studio 3.0 and update the gradle build tool version to 3.0.0, compiling of dependencies is now done differently than in earlier versions.

I recently encountered the same issue. I was using these dependencies which worked fine through Gradle version 2.3.3:

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

After the upgrade to gradle-build-version 3.0.0, I got the same error. Digint into it, I found that the transitive dependency of httpmime conflicted with the file httpclient-android was including.

Description

Let me explain this in detail. Earlier, while using gradle-tool-version 2.3.3, I was using httpclient-android to fetch and use the class named org.apache.http.entity.ContentType.java Expanding the transitive dependencies of org.apache.httpcomponents:httpmime:4.3.6 showed that it has org.apache.httpcomponents:httpcore:4.3.6 which is the same package I wanted to use. But while compiling or syncing the build, it was excluding 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'

Everything worked fine after that.

Once I upgraded the gradle-build-version to 3.0.0, things changed. It now included all transitive dependencies. So while compiling with the latest Android Studio with gradle-build-tool version 3.0.0, my ContentType.java was being compiled twice. Once from org.apache.httpcomponents:httpcore:4.3.6 (which is an implicit transitive dependency of httpmime) and again from org.apache.httpcomponents:httpclient-android:4.3.5.1 which I was using earlier.

To resolve this issue I had to remove the existing org.apache.httpcomponents:httpclient-android:4.3.5.1 dependency as httpmime would itself fetch the relevant class required for my application.

The solution for my situation: only use required dependencies and remove the httpclient-android

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

Note that this is just the case for me. You'll need to dig into your own dependencies and apply the solution accordingly.