I have Android Studio Beta. I created a new project with compile my old modules but when I tried launching the app it did not launch with the message:
Error:
[ UNABLE TO MERGE DEX SOLVED ] After hours of stack overflowing I resolved the " UNABLE TO MERGE DEX ERROR "
Cause - Android has updated it support libraries to v27.1.0, so you have to change all the android support lines in your gradle file to 27.1.0 from 26.1.0
Make sure that the repositories section includes a maven section with the "https://maven.google.com" endpoint. For example:
allprojects { repositories { jcenter() maven { url "https://maven.google.com" } } }
Cause :- Android cannot update the support libraries in the SDK manager and now it uses maven.google.com to update , so you have to include this to use 27.1.0 support libraries
After Change Version: 1. Clean Project 2. Rebuild Project
I had the same problem when I update from com.google.android.gms:play-services:11.2.2
to com.google.android.gms:play-services:11.4.0
. This solved it for me:
I tried every other solution, but no one worked for me. At the end, i solved it by using same dependency version by editing build.gradle
. I think this problem occurres when adding a library into gradle which uses different dependency version of support or google libraries.
Add following code to your build gradle file. Then clean
and rebuild
project.
ps: that was old solution for me so you should use updated version of following libraries.
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.1.0'
}
} else if (requested.group == "com.google.android.gms") {
details.useVersion '11.8.0'
} else if (requested.group == "com.google.firebase") {
details.useVersion '11.8.0'
}
}
}
For me it was updating the firebase messaging in app\build.gradle:
compile 'com.google.firebase:firebase-messaging:10.0.1'
to
compile 'com.google.firebase:firebase-messaging:11.4.2'
In case the top answers haven't worked for you, your issue may be that you have multiple dependencies that depend on the same library.
Here are some debugging tips. In this sample code, com.google.code.findbugs:jsr305:3.0.0
is the offending library.
Always clean and rebuild every time you modify to check your solution!
Build with the --stacktrace
flag on for more detail. It will complain about a class, Google that class to find the library. Here's how you can set up Android studio to always run gradle with the --stacktrace flag.
Take a glance at the Gradle Console in Android Studio View > Tool Windows > Gradle Console
after a build
Check for repeated dependences by running ./gradlew -q app:dependencies
. You can re-run this each time you modify the your build.gradle.
In build.gradle,
android {
...
configurations.all {
resolutionStrategy {
// Force a particular version of the library
// across all dependencies that have that dependency
force 'com.google.code.findbugs:jsr305:3.0.0'
}
}
}
In build.gradle,
dependencies {
...
implementation('com.google.auth:google-auth-library-oauth2-http:0.6.0') {
// Exclude the library for this particular import
exclude group: 'com.google.code.findbugs'
}
}
In build.gradle,
android {
...
configurations.all {
resolutionStrategy {
// Completely exclude the library. Works for transitive
// dependencies.
exclude group: 'com.google.code.findbugs'
}
}
}
If some of your dependencies are in jar files, open up the jar files and see if there are any conflicting class names. If they are, you will probably have to re-build the jars with new class names or look into shading.
Some more background reading:
Sometimes you only need to eliminate warnings and the error will be disappeared automatically. See below special case:
I had these two dependencies in my module-level build.gradle
file:
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
and Studio had warned (in addition to dex merging problem):
All
com.android.support
libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions27.0.2
,21.0.3
. Examples includecom.android.support:animated-vector-drawable:27.0.2
andcom.android.support:support-v4:21.0.3
So I explicitly determined the version of com.android.support:support-v4
(see here for details) and both problems (the warning and the one related to dex merging) solved:
implementation 'com.android.support:support-v4:27.0.2' // Added this line (according to above warning message)
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
See below comments for other similar situations.