Unable to Merge Dex - Android Studio 3.0.1 DexArchiveMergerException
I have solved after try all the solutions on stackoverflow, try to do the following steps in its order
- Replace all compile with implementation
- Make all supportLibraryVersion = '27.0.2'
- Change
'com.google.android.gms:play-services-maps:11.8.0'
to
'com.google.android.gms:play-services-maps:11.4.0'
- Remove all the unused library
- Delete the .gradle folder inside your project
- Remove build folders and the gradle cache
- file -> invalidate caches/restart
- Build > Clean Project
- Add
dependencies { implementation 'com.android.support:multidex:1.0.1'}
- Add
android {
defaultConfig {
multiDexEnabled true
}
}
- Async project
And finally this is my App file
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example"
minSdkVersion 18
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
ext {
supportLibraryVersion = '27.0.2'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
//constraint
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//butterknife
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//avi:library
implementation 'com.wang.avi:library:2.1.3'
//circleimageview
implementation 'de.hdodenhof:circleimageview:2.2.0'
//retrofit2
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.squareup.okhttp3:okhttp:3.8.0'
implementation 'com.jakewharton.retrofit:retrofit1-okhttp3-client:1.0.2'
//recyclerview and cardview
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support:cardview-v7:27.0.2'
//ZXing for barCode reader
implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
implementation 'com.google.zxing:core:3.2.1'
//play-services
implementation 'com.google.android.gms:play-services-maps:11.4.0'
//gson
implementation 'com.google.code.gson:gson:2.8.2'
//statusbarutil
implementation 'com.jaeger.statusbarutil:library:1.4.0'
//glide
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
//multidex
implementation 'com.android.support:multidex:1.0.1'
}
ِِActually I didn't understand the real reason about it and why that happened suddenly
So if anyone know that please tell me with full details
I hope this will help you
Unable to merge DEX in Android Studio 3.0.1 even after enabling multidex
This isn't a multidex problem...it's a dependency merge conflict issue.
By the looks of it one of your dependencies has a sub-dependency on CoordinatorLayout
but has specified a different version from the one which you are using. You can fix this by using a resolutionStrategy
in your build.gradle
to define the version of the support library to use.
First make a variable to define your support library version:
ext {
supportLibVersion = "26.1.0"
}
Then update your dependences to use this variable rather than the hard coded value (note the double quotes):
implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.android.support:design:${supportLibVersion}"
Then you can add a resolutionStrategy
to your build.gradle
:
configurations.all {
resolutionStrategy.eachDependency { details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion "${supportLibVersion}"
}
}
}
}
What this does is ask Gradle to ignore the version number specified in with the dependency and use your version.
Unable to merge dex Android Studio 3.0
Use this
implementation 'com.firebaseui:firebase-ui-database:3.3.0'
implementation 'com.google.android.gms:play-services-auth:12.0.1'
implementation 'com.google.android.gms:play-services-maps:12.0.1'
implementation 'com.google.firebase:firebase-database:12.0.1'
implementation 'com.google.firebase:firebase-storage:12.0.1'
implementation 'com.google.firebase:firebase-auth:12.0.1'
implementation 'com.google.firebase:firebase-core:12.0.1'
Instead of this
implementation 'com.firebaseui:firebase-ui-database:3.2.1'
implementation 'com.google.android.gms:play-services-auth:12.0.0'
implementation 'com.google.android.gms:play-services-maps:12.0.0'
implementation 'com.google.firebase:firebase-database:12.0.0'
implementation 'com.google.firebase:firebase-storage:12.0.0'
implementation 'com.google.firebase:firebase-auth:12.0.0'
implementation 'com.google.firebase:firebase-core:12.0.0'
Unable to Merge Dex - Android Studio 3.0
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.
Unable to merge dex - android studio 3.0 update
I think some problem is with Your versions.
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
...
Maybe order in this is problem.
Try this. I hope it will work.
Related Topics
Android Studio: Unable to Start the Daemon Process
How to Tell Which App Was Selected by Intent.Createchooser
Start a Fragment via Intent Within a Fragment
Render Error in Android Studio 3.0 Layout Editor
How to Create Always-Top Fullscreen Overlay Activity in Android
How to Run Opencv Code Without Opencv Manager
How to Set Spinner Default Value to Null
How to Show Progress Dialog in Android
How to Execute a Method by Clicking a Notification
Inserting Contacts in Android 2.2
Anr Keydispatchingtimedout Error
How to Pop Fragment Off Backstack
Android Listview Setselection() Does Not Seem to Work
Error:Program Type Already Present: Android.Support.Design.Widget.Coordinatorlayout$Behavior