Unable to merge dex
Asked Answered
P

63

325

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:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

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

But I don't know how to solve this error. I googled this for hours but with no success.

My project gradle:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-beta6'
        classpath "io.realm:realm-gradle-plugin:3.7.1"
        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
}

My app gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "parad0x.sk.onlyforyou"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
        }
    }
    compileOptions {
        targetCompatibility 1.7
        sourceCompatibility 1.7
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }
    lintOptions {
        checkReleaseBuilds false
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //noinspection GradleCompatible
    compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
    compile project(path: ':loginregisterview')


}

And my module gradle:

    apply plugin: 'com.android.library'
apply plugin: 'realm-android'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    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:appcompat-v7:26.0.2'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.github.bumptech.glide:glide:4.0.0'
    testCompile 'junit:junit:4.12'
    compile project(path: ':parser')

}

My second module:

     apply plugin: 'com.android.library'
apply plugin: 'realm-android'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    realm {
        syncEnabled = true
    }
    useLibrary 'org.apache.http.legacy'

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile 'junit:junit:4.12'
    //  compile 'com.android.support:appcompat-v7:23.1.0'

    //   compile 'com.fasterxml.jackson.core:jackson-core:2.9.0'
 //   compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
 //   compile 'com.fasterxml.jackson.core:jackson-databind:2.9.0'
    compile 'com.google.code.gson:gson:2.6.2'
}

____________finding_________

When I did not import the second module (parser) the app did not crash on dex but when the module was not imported app did not work. :D :D

Pierce answered 17/9, 2017 at 18:42 Comment(2)
If anyone is getting the same issue in Android Studio 3.0 Stable version, I would strongly recommend you to review the answer #46950261 and see if it can help you.Denims
I had the same problem and I followed every method which is mentioned on this page but didn't help me out so I go to the gradle and hold cursor on each library to check their new version is available or not. those who have new version so I updated, sync gradle and run. it worked.Hosfmann
C
301

I had the same problem when I updated 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:

  1. clean
  2. rebuild

And also pay attention if you use more libs add multiDexEnabled true

Collie answered 23/9, 2017 at 21:52 Comment(6)
You only delay the real problem with that solution. probably ver 11.4.0 contains less methods. See my answer below. you will got this error in the next dependence you'll add I guessToady
This solves my issue, where multiDexEnabled true alone did notMufti
same isse with com.google.android.gms:play-services-location:11.6.0 ... this is not a valid solutionStirk
This solution worked for me when I had a compatibility problem using google analytics libraries. In AS view the android project navigator pane as "Project", you should see "External Libraries", if you expand the external libraries, you'll see all the jars and modules used to compile the project. It should help you identify incompatible module combinations.Doughy
If above code is not work in case of "compileSdkVersion 26", try this.. go to - build.gradle(Module:app) - add " multiDexEnabled true " in defaultConfig category and last step Go to File | Settings | Build, Execution, Deployment | Instant Run and try to Enable/DisableJotham
Error:Execution failed for task ':app:processDebugGoogleServices'. > Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at bintray.com/android/android-tools/…) or updating the version of com.google.android.gms to 11.4.0.Dispeople
T
359

I tried all the above and none of them helps. finally, I find this work for me:

app/build.gradle:

android {
    defaultConfig {
       multiDexEnabled true
    }
}
Toady answered 5/10, 2017 at 16:55 Comment(6)
Thanks. I think the problem was that most answers are not accounting for including JAR files from other sources that you cannot rebuild. multiDex seems to allow the otherwise incompatible code to be combined.Advisedly
This solution worked for me, but in addition, I had to explicitly enable multidex for API <= 21 developer.android.com/studio/build/multidex.htmlStentor
DEspite being more relevant than the accepted answer I still get "Unable to merge dex" messageAbatis
Also needed to add multiDexEnabled true for all modulesDannydannye
Didn't work for me. With this change I got different error: Execution failed for task ':app:transformClassesWithMultidexlistForDebugUndistinguished
Yes for 5 hours i was dwelling with totally different answers. But somehow I realized it was Multidex issue and landed here. I was true. Thanks manJocelyn
C
301

I had the same problem when I updated 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:

  1. clean
  2. rebuild

And also pay attention if you use more libs add multiDexEnabled true

Collie answered 23/9, 2017 at 21:52 Comment(6)
You only delay the real problem with that solution. probably ver 11.4.0 contains less methods. See my answer below. you will got this error in the next dependence you'll add I guessToady
This solves my issue, where multiDexEnabled true alone did notMufti
same isse with com.google.android.gms:play-services-location:11.6.0 ... this is not a valid solutionStirk
This solution worked for me when I had a compatibility problem using google analytics libraries. In AS view the android project navigator pane as "Project", you should see "External Libraries", if you expand the external libraries, you'll see all the jars and modules used to compile the project. It should help you identify incompatible module combinations.Doughy
If above code is not work in case of "compileSdkVersion 26", try this.. go to - build.gradle(Module:app) - add " multiDexEnabled true " in defaultConfig category and last step Go to File | Settings | Build, Execution, Deployment | Instant Run and try to Enable/DisableJotham
Error:Execution failed for task ':app:processDebugGoogleServices'. > Please fix the version conflict either by updating the version of the google-services plugin (information about the latest version is available at bintray.com/android/android-tools/…) or updating the version of com.google.android.gms to 11.4.0.Dispeople
C
61

Pay attention to Warnings!

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 versions 27.0.2, 21.0.3. Examples include com.android.support:animated-vector-drawable:27.0.2 and com.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.

Celeriac answered 11/1, 2018 at 21:22 Comment(4)
Thank you, this fixed the issue for me. It was originally caused by adding eu.inloop:androidviewmodel:1.3.4Induce
Exactly, I just wish the error could have been more preciseShamikashamma
Thanks a lot. I had the same issue. I was using v26, updated to sdk 27 and solved the problem.Nieberg
This should be the correct answer. My builds stopped working after adding one library (airbnb/epoxy) which had a dependency to support:design:26.1.0, and I didn't have that dependency yet. My others support libraries version was 27.1.0. After adding support:design dependency with 27.1.0 version, my issue was resolved.Traylor
C
37

In my case, Unfortunately, neither Michel's nor Suragch's solutions worked for me.

So I solved this issue by doing the following:

In gradle:3.0 the compile configuration is now deprecated and should be replaced by implementation or api. For more information you can read here You can read the official docs at Gradle Build Tool

The compile configuration still exists but should not be used as it will not offer the guarantees that the api and implementation configurations provide.

it's better to use implementation or api rather compile

just replace compile with implementation, debugCompile with debugImplementation, testCompile with testImplementation and androidtestcompile with androidTestImplementation

For example: Instead of this

compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.github.bumptech.glide:glide:4.0.0'

use like this

implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.github.bumptech.glide:glide:4.0.0'

After that

  • Delete the .gradle folder inside your project ( Note that, in order to see .gradle, you need to switch to the "Project" view in the navigator on the top left )
  • Delete all the build folders and the gradle cache.
  • From the Build menu, press the Clean Project button.
  • After task completed, press the Rebuild Project button from the Build menu.

Hope it will helps !

Caril answered 15/11, 2017 at 9:46 Comment(9)
Thanks, all I had to do was change compile to implementation and it built successfully, didn't have to complete the other steps. The build started failing after I updated the Facebook SDKPrado
Worked for me - insights into why?Crocker
The folder to delete should be .gradle and not ./gradleBimetallic
Also testImplementation instead of testCompile.Connote
I already mentioned it in my answer. anyways thanks for sayingCaril
Why would implementation work and compile won't? They should have made it backward compatible. Anyways thanks a lot!Lammastide
The only answer that actually worked for me. Thanks!Khajeh
Where is the "gradle cache"?Chas
Thanks, It is the coolest answer. It should be on top of the search. Worked for me.Ant
I
32
  1. Delete the .gradle directory.

  2. Run your app again.

Notes

  • The .gradle directory is in your project's root folder. (You may have to show hidden files first.)
  • I have to do this every time I update a dependency module using Android 3.0. (More recent releases of Android Studio 3 seem to have resolved the problem.)
Idea answered 18/9, 2017 at 8:31 Comment(2)
this helped me when I also did a Invalidate Cache and restartRajasthani
I was in disbelief when this fixed my issue.. i had tried updating everything, removing all compile keywords, updating a few of the suspect ilb versions.. when i finally did this, it worked..Lingerie
C
26

Deleting .gradle as suggested by Suragch wasn't enough for me. Additionally, I had to perform a Build > Clean Project.

Note that, in order to see .gradle, you need to switch to the "Project" view in the navigator on the top left:

Switch to project view

Correlate answered 19/9, 2017 at 7:12 Comment(0)
A
23

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'
          }
      }
}
Absorbent answered 21/3, 2018 at 9:7 Comment(6)
tried all other solutions, in the end only this helped :/Trussing
@Ali Gurelli Thank you so much i tried many solutions but only this work only.Cretin
Thanx But For me I use Version details.useVersion '15.0.0'Oneidaoneil
Thanks for solution. Same issue happened to me . google tap and pay was 10.0.0 and rest all libs are on latest versionPeg
Worked Smoothly ThanksConductive
I need to tell, you saved my morning!Estrada
F
17

if(1. Try to clean and rebuild work ) then good

else if (2. Try to remove gradle work ) then good

else-> 3. Try to add in grade.properties

android.enableD8 = false

Edit 2021: This 3rd option is deprecated now, use the other options

else-> 4. Add multiDexEnabled true to your build.gradle

android {
    compileSdkVersion 26
    defaultConfig {
      ...
        minSdkVersion 15
        targetSdkVersion 26
        multiDexEnabled true
     ...
    }
}

and add the dependency

dependencies {
    compile 'com.android.support:multidex:1.0.1'}

It may the first one works for u and so on but it really depends on the nature of your problem for me for example

I got the error once I have added this library

implementation 'com.jjoe64:graphview:4.2.2'

and later I discovered that I have to check that and I have to add the same version of the support libraries. So I have to try another version

compile 'com.jjoe64:graphview:4.2.1'

and it fixes the problem. So pay attention for that.

Fashion answered 14/5, 2018 at 23:16 Comment(2)
The most useful way for this problem. One I want to mention here is that, you can use 'gradlew app:transformDexArchiveWithExternalLibsDexMergerForDebug --stacktrace' cmd for more details. I save me, found I have to enable multidex. Hope helpful.Semiautomatic
@DINA, android.enableD8 = false is deprecated.Bugbear
E
13

In my case issue was because of the room library:

compile 'android.arch.persistence.room:runtime:1.0.0-alpha1'

Changing it to:

compile 'android.arch.persistence.room:runtime:1.0.0'

worked.

Execrative answered 1/12, 2017 at 5:21 Comment(2)
Thanks so much, this helped me a lot!Nosedive
So glad to find this answer. Thanks!Toluate
S
12

Just to add to the above solutions:

Make sure that you don't have duplicate dependencies pointing to different versions of them, in multiple places (or even in the same file).

Sometime answered 29/11, 2017 at 23:32 Comment(1)
I think this should be first check before adding multiDexEnabled true, and trying other answers. Thanks!Wader
D
11

Hi I have same issue tried almost everything. So, finally i resolved after 6 hour long struggle by debugging everything line by line.

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

Google-services 3.0 Doesn't support firebase with Studio 3.0 with playServiceVersion: 11.6.0 or less.

implementation "com.google.firebase:firebase-messaging:$rootProject.ext.playServiceVersion"
implementation "com.google.firebase:firebase-core:$rootProject.ext.playServiceVersion"
implementation "com.firebase:firebase-jobdispatcher-with-gcm-dep:$rootProject.ext.jobdispatcherVersion"

Solution :

I have change google services to

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

And it support firebase services.

Hopefully somebody save his/her time.

Dragelin answered 18/11, 2017 at 17:52 Comment(1)
I have the same issue I was using playServiceVersion as 11.4.0 implementation "com.google.firebase:firebase-core:11.4.0" change it to implementation "com.google.firebase:firebase-core:11.6.2" fixed my issue . So please verify the version dependency for different libBombastic
M
9
  1. Enable

    defaultConfig { multiDexEnabled true }

  2. If step 1 doesn't work then

    Go to project structure and find out the external library which is using a different version. Double click on it and delete its jar file. Close the project and open again android studio will rebuild the project. The problem should be gone.

Marin answered 12/1, 2018 at 9:31 Comment(1)
+1 - I had the support lib, rxjava and a 3rd party dependency (13k lines). My eyes nearly popped out when I saw the method count.Burnsed
T
6

One of the possibilities is: the presence of the same library but with different versions in the dependencies.

I had this problem with the following lines in gradle file:

  • compile fileTree(include: ['*.jar'], dir: 'libs')
  • compile 'com.google.code.gson:gson:2.8.2'

The gson library was in my libs directory but with a previous version. I deleted the gson-2.3.1.jar from the libs directory and everything is back to normal.

Toxoplasmosis answered 28/12, 2017 at 14:31 Comment(1)
removing compile fileTree(include: ['*.jar'], dir: 'libs') fixed for me too.. thanks (y)Kalina
G
5

If this error appeared for you after including kotlin support, and none of the other solutions work, try changing the kotlin dependency of app module's build.gradle to:

implementation ("org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version") {
    exclude group: 'org.jetbrains', module: 'annotations'
}

This works for me on Android Studio 3.0 Beta 6. See this answer for further explanation.

Grisly answered 2/10, 2017 at 18:50 Comment(3)
Yep, it seems that Kotlin introduction could break the build if the annotations are not excluded.Consentaneous
Thanks. This was the fix for me. I struggle 3 days to identify my problem.Rhizotomy
Try upgrading to Kotlin plugin version 1.2.30 instead (just released). Now Instant Run can be enabled again too!Gap
C
5

With Android Studio 3.0 stable build Below steps worked for me:

  1. Got to SdkManager-->Android Sdk --> Sdk Tools and Update Google play services to latest version to 46.
  2. Clean project and rebuild project.
Cocainism answered 27/10, 2017 at 7:55 Comment(0)
R
5

[ UNABLE TO MERGE DEX SOLVED ] After hours of stack overflowing I resolved the " UNABLE TO MERGE DEX ERROR "

  1. Update all the com.android.support lines in your gradle to v27.1.0

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

  1. 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

Redmon answered 12/3, 2018 at 19:11 Comment(0)
F
4

add commands below:

android {
...

    dexOptions {

        jumboMode true
        javaMaxHeapSize "4g"

    }
}
Fluted answered 30/10, 2017 at 7:36 Comment(0)
V
4

Installing Google play services (latest version) + including

android {
    defaultConfig {
        multiDexEnabled true
        }
}

in build.gradle solved the issue for me, make sure to clean and rebuild project!

Vicious answered 21/12, 2017 at 0:4 Comment(0)
B
3

I agree with Chris-Jr. If you are using Firebase to embed your AdMob ads (or even if you are not) the play-services-analytics includes the play-services-ads even though you don't add that as a dependency. Google have obviously made a mistake in their 11.4.0 roll-out as the analytics is including version 10.0.1 of ads, not 11.4.0 (the mouse over hint in the gradle shows this).

I manually added compile 'com.google.android.gms:play-services-ads:11.4.0' at the top which worked, but only after I disabled Instant Run: https://mcmap.net/q/100813/-instant-run-in-android-studio-2-0-how-to-turn-off

So its either regress to 10.0.1 or add the ads and disable Instant Run. That's what I found if it helps any.

Branson answered 24/9, 2017 at 9:10 Comment(2)
Did OP mention Play Services?Characharabanc
The approved answer did. If this issue is surfacing without that scenario then I don't know!Branson
R
3

In my case it was gson-2.8.1.jar which I have added to libs folder of the project. But the reference was already there by SDK. So it was not necesary to add gson-2.8.1.jar to libs folder.

When I took it out th gson-2.8.1.jar project compiles without this wiered error.

So try to revise libs folder and dependencies.

Rosie answered 11/12, 2017 at 2:27 Comment(0)
P
2

I encountered the same problem and found the real reason for my case. Previously, I also tried all the previous answers again, but it did not solve the problem. I have two module in my wear app project, and the build.gradle as follows:

wear module's build.gradle:

implementation project(':common')
implementation files('libs/farmer-motion-1.0.jar')

common module's build.gradle:

implementation files('libs/farmer-motion-1.0.jar')

Before upgrade to gradle 3.x, 'implementation' are all 'compile'.

I run gradlew with --stacktrace option to get the stack trace, you can just click this on gradle console window when this problem arises. And found that dependency to the jar package repeated:

Caused by: com.android.dex.DexException: Multiple dex files define Lcom/farmer/motion/common/data/pojo/SportSummary$2;

Class SportSummary in the farmer-motion-1.0.jar package, after read the official migration guide, i changed my build.gradle to follows:

wear module's build.gradle:

implementation project(':common')
// delete dependency implementation files('libs/farmer-motion-1.0.jar')

common module的build.gradle:

api files('libs/farmer-motion-1.0.jar') // change implementation to api

Now wear module will has the dependency of farmer-motion-1.0.jar export by common module. If there has no dependency on jar package during runtime, 'implementation' dependency of jar package can also be change to 'compileOnly'.

Postgraduate answered 19/1, 2018 at 6:20 Comment(0)
V
2

I also had the problem.

I was able to solve by changing compileSdkVersion and targetSdkVersion to latest version.

Veronaveronese answered 3/3, 2018 at 13:12 Comment(0)
U
2

For our project, we accidentally added same jar two times with different name. Removing one of them solved the issue.

Underbodice answered 22/3, 2018 at 8:58 Comment(1)
This solved my issue. I was building an internal android library project and under its libs folder, I had two jar files, one of which is just a backup of the other one but with a different filename.Attire
M
2

This may not be your problem, but I got this error when I accidentally included two identical (but differently named) libraries in the dependencies{} section of the project.

Marquettamarquette answered 10/7, 2018 at 22:9 Comment(0)
T
1

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'
Tatter answered 4/11, 2017 at 8:47 Comment(0)
C
1

One of possible root causes: duplicate transient dependencies that weren't properly handled by Android Studio import of multi-module projects. Check your list and remove them. For me, the fix was literally this:

--- a/project/module/build.gradle
+++ b/project/module/build.gradle
@@ -21,5 +21,4 @@ android {
 dependencies {
     implementation project(':upstream-dependency-project')
     implementation 'com.android.support:support-v4:18.0.0'
-    implementation files('libs/slf4j-android-1.6.1-RC1.jar')
 }
Cynthla answered 27/11, 2017 at 23:53 Comment(0)
B
1

I find out the reason of this problem for my project. I was added one dependency twice in build.gradle. One time by adding dependency and one time again by adding jar dependency:

compile 'org.achartengine:achartengine:1.2.0'
...
implementation files('../achartengine-1.2.0.jar')

after remove the first line problem solved.

Benefic answered 23/1, 2018 at 9:23 Comment(0)
D
1

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!

  1. 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.

  2. Take a glance at the Gradle Console in Android Studio View > Tool Windows > Gradle Console after a build

  3. Check for repeated dependences by running ./gradlew -q app:dependencies. You can re-run this each time you modify the your build.gradle.

  4. 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'
                }
            }
    }
    
  5. 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'
        }
    }
    
  6. In build.gradle,

    android {
        ...
        configurations.all {
            resolutionStrategy {
                // Completely exclude the library. Works for transitive
                // dependencies.
                exclude group: 'com.google.code.findbugs'
            }
        }
    }
    
  7. 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:

Dirham answered 16/2, 2018 at 3:45 Comment(0)
S
1
android {
    defaultConfig {
        ...
        minSdkVersion 15 
        targetSdkVersion 26
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}
Storiette answered 18/3, 2018 at 11:51 Comment(2)
Could you elaborate?Wirra
I also had the same problem but I realized that solve my problem at that moment but in the future updates, things might actually change.Storiette
A
1

In my case a library makes this problem, library was successfully added to project but when i run my app it shows me this error. So if this happens to you too, you can go to github and check issues or raise new issue. If you do not find any solution regarding the library i suggest you to replace it.

Auctioneer answered 24/9, 2018 at 16:30 Comment(0)
A
1

I had same problem. I just enabled Instant Run(It was disabled) then my project worked. You can find it in-

File->Settings-> Build,Execution,Deployment->Instant Run

In Android studio 3.5 Instant Run have been removed. Please see here for reference

Atrice answered 11/3, 2019 at 9:59 Comment(2)
There is no Instant Run in the path called "Build, Execution, Deployment" your answer has no meaning.Backside
@Backside in Android studio 3.5 Instant Run is not available.My answer updated.Atrice
M
0

Unfortunately, neither Michel's nor Suragch's solutions worked for me.

What I eventually had to do was simply rollback my com.google.firebase:firebase-database to version 10.0.1, since 11.4.0 was causing a dependency inconsistency warning in my app gradle file.

Margalit answered 23/9, 2017 at 0:5 Comment(0)
H
0

In my case, I import one 'android_support' lib twice ,so I delete one under 'libs' directory and rebuild.

Hampson answered 15/11, 2017 at 8:28 Comment(0)
S
0

try like this, it works for me.

In app/build.gradle:

dependencies {
    ....

    compile project(':grow-notification')

    /** Firebase Start **/
    compile 'com.google.firebase:firebase-messaging:11.4.0'
    compile 'com.firebase:firebase-jobdispatcher:0.6.0'
    /** Firebase End **/
}

apply plugin: 'com.google.gms.google-services'

while in module grow-notification/build.gradle:

dependencies {
    ....

    /** Firebase Start **/
    provided 'com.google.firebase:firebase-messaging:11.4.0'
    provided 'com.firebase:firebase-jobdispatcher:0.6.0'
    /** Firebase End **/
}
Strobilaceous answered 2/12, 2017 at 6:25 Comment(0)
B
0

In my case the problem was I implemented the same library twice in my build.gradle file. Removing the duplicate entry worked for me. And did not even needed to clean, rebuild the project.

Backwards answered 2/12, 2017 at 14:35 Comment(0)
B
0

Simple solution worked for me:

  1. Don't compile/implement two versions of same dependencies.
  2. Don't use .jar file in libs folder of your project, if you are compiling it directly from gradle. Above point applies here too.

Then Clean and Rebuild project.

Bereniceberenson answered 6/12, 2017 at 13:15 Comment(2)
How to know it? Don't compile/implement two versions of same dependencies.Rosie
'com.google.firebase:firebase-messaging:10.0.1' with different version 'com.google.firebase:firebase-messaging:11.0.2' or a .jar file in libs with firebase-messaging**-**12.3.2.jarBereniceberenson
T
0

I had the same problem. I solved it by performing a clean and then building the project from Android Studio 3.0 menu:

  1. build -> clean project
  2. build-> rebuild project
Theravada answered 9/12, 2017 at 13:55 Comment(1)
It does not helpRosie
Y
0

For most of cases this works. It works for me . Good Luck if it works for you too.

Step 1:In build.gradle (Module:app) add this: defaultConfig{ multiDexEnabled true }

Step 2: do this: Build=> Clean Project

Step 3: do this: Build=> Rebuild Project

Younglove answered 11/12, 2017 at 4:41 Comment(0)
S
0
./gradlew :app:assembleStubLiveDebug -debug -stacktrace

Or similar (get the task name (:app:assembleStubLiveDebug) from Android Studio).

Sparoid answered 12/12, 2017 at 3:39 Comment(0)
O
0

It is a common problem when you have added two version of the same library..either in the dependency or in the library....It my case and almost every time this fixes the issue..

Oilskin answered 17/12, 2017 at 15:30 Comment(0)
S
0

In my project I have more then two modules and sdks, I try all suggestion or answer listed above like

  • add multiDexEnabled true in defaultConfig
  • Clean and Rebuild project
  • replacing compile with implementing
  • update all dependencies

All these work temporarily but when I open project structure(cntrl + altr + shift+ s) i found, In my Project Property nothing will selected like- - compile SDK version, build sdk version - In flavors same

I update all these and perform clean and rebuild project and it works for me.

Sulky answered 26/12, 2017 at 8:58 Comment(0)
B
0
    android {
        defaultConfig {
            multiDexEnabled true
            }
    }

   compile 'com.google.android.gms:play-services:11.0.4'

   compile 'com.google.android.gms:play-services-location:11.0.4'

build clean and build Rebuild

Buckra answered 11/1, 2018 at 5:45 Comment(0)
J
0

After upgrading some dependency I found solutions. We should use latest play service version. In build.gradle[app] dependency.

compile 'com.android.support:multidex:1.0.2'
compile 'com.google.android.gms:play-services:11.8.0'
compile 'com.google.firebase:firebase-core:11.8.0'

In build.gradle[project], we should use latest Google plug-in.

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

I am also sharing below code for better understanding.

    android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.***.user"
        minSdkVersion 17
        targetSdkVersion 26
        versionCode 26
        versionName "1.0.20"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true

        aaptOptions {
            cruncherEnabled = false
        }

    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
Jammie answered 28/1, 2018 at 6:50 Comment(0)
S
0

For me the issue was that 2 of the jars that I included in the project had the same classes in them.

For 1 of these jars I needed to exclude the classes:

jar {
    exclude('com/files/to/exclude/**')
}
Sprightly answered 29/1, 2018 at 11:6 Comment(0)
C
0

In my case the error was importing the dependency:

implementation 'com.firebaseui:firebase-ui:2.3.0'

and I was not using it, it started working when I deleted it cleaned project and recomplied. Of course I also did what the people above did which was:

  • Changing complie to implementation throughout the whole app.grade
  • Changing testcomplie to testimplementation throughout the whole app.grade
  • Make sure I have multidexenabled true
  • Update compileSdk to 26
  • Deleted .gradle file (found in project), clean project and recompile

and finally...

  • Deleted implementation 'com.firebaseui:firebase-ui:2.3.0' (Since I was not using it in my code)
Calvary answered 31/1, 2018 at 20:35 Comment(0)
J
0

There might be a duplicated dependency (possibly nested in another dependency). Use "gradlew app:dependencies" in the command-line to verify all of your dependencies.

After removing duplicates, the problem was solved for me.

Jandy answered 14/2, 2018 at 22:45 Comment(0)
T
0

I spend more than 3 hours reading and testing all the responses. Finally the problem was the library "joda time",

Reading this answer I found the problem, run the gradle console with full stack trace and read the error detail.

Tardiff answered 20/2, 2018 at 10:11 Comment(0)
C
0
    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.xyz.name"
        minSdkVersion 14
        targetSdkVersion 27
        versionCode 7
        versionName "1.6"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    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.volley:volley:1.0.0'
    implementation 'com.wang.avi:library:2.1.3'
    implementation 'com.android.support:design:27.1.0'
    implementation 'com.android.support:support-v4:27.1.0'
    implementation 'de.hdodenhof:circleimageview:2.1.0'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.google.firebase:firebase-messaging:11.8.0'
    implementation 'com.felipecsl.asymmetricgridview:library:2.0.1'
    implementation 'com.android.support:recyclerview-v7:27.1.0'
    implementation 'com.github.darsh2:MultipleImageSelect:3474549'
    implementation 'it.sephiroth.android.library.horizontallistview:hlistview:1.2.2'
    implementation 'com.android.support:multidex:1.0.1'
}

apply plugin: 'com.google.gms.google-services'

Note: update your all support library to 27.1.0 like above and remove duplicates

Chordophone answered 1/3, 2018 at 5:55 Comment(0)
E
0

check dependencies version if they are not same then make it same it will solve your problem

compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:recyclerview-v7:27.0.2'
compile 'com.android.support:cardview-v7:27.0.2'
Entomb answered 7/3, 2018 at 11:53 Comment(0)
L
0

Check if you have debugCompile and releaseCompile in build.gradle. Change it to debugImplementation and releaseImplementation. This was how I have solved it, gradle should pass through this successfully marked instructions as deprecated, but suddenly it stucked exactly on this two.

Limelight answered 25/3, 2018 at 9:19 Comment(0)
S
0

Make sure all same source library have same version number. In my case I was using different google api versions. I was using 11.6.0 for all google libraries but 10.4.0 for google place api. After updating google place api to 11.6.0, problem fixed.

Please note that my multidex is also enabled for the project.

Sato answered 3/4, 2018 at 17:22 Comment(0)
E
0

Change you buildToolsVersion to some other version and sync, change it back and sync again. It will work again.

Embry answered 4/5, 2018 at 18:1 Comment(0)
B
0

If you are using Firebsae in your plugin, this issue will come due to play services version issue, try this `cordov

cordova.system.library.4=com.google.gms:google-services:3.3.0
    cordova.system.library.5=com.google.android.gms:play-services-tagmanager:+
    cordova.system.library.6=com.google.firebase:firebase-core:16.0.1
    cordova.system.library.7=com.google.firebase:firebase-messaging:17.1.0
    cordova.system.library.8=com.google.firebase:firebase-crash:16.0.1
    cordova.system.library.9=com.google.firebase:firebase-config:16.0.0
    cordova.system.library.10=com.google.firebase:firebase-perf:16.0.0 

Change your project.properties like this, then this issue will be resolved Reference

Bidarka answered 12/7, 2018 at 14:20 Comment(0)
Z
0

This works for me-

Add code at last in platforms\android\build.gradle

configurations.all { 
 resolutionStrategy{
    force 'com.android.support:support-v4:26.0.0'
    }

    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
    def requested = details.requested
    if (requested.group == 'com.android.support') {
       if (!requested.name.startsWith("multidex")) {
      details.useVersion '26.0.0'
     }
   }
  }
}
Zero answered 14/1, 2019 at 11:38 Comment(0)
B
0

add this in your app/build.gradle. It will work

implementation 'com.android.support:design:27.1.0'

Bali answered 6/5, 2019 at 17:3 Comment(0)
S
0

Just add below in build.gradle,

defaultConfig { multiDexEnabled true }

Siqueiros answered 22/5, 2019 at 12:54 Comment(1)
Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.Caveat
G
0

This hasn't been shared here yet so hopefully it can help someone.

Following this link solved the same issue for me.

To begin, I'll note that I did not have to set multiDexEnabled to true.

First I set dependencies in my pubspec.yaml to

dependencies:
  flutter:
    sdk: flutter
  cloud_firestore: ^0.8.2 

and ran flutter packages get in my IDE's terminal.

Also I had to change the minimum target SDK version:

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

This alone may fix your problem; however I had to also do the following because some of my dependency versions were mismatched.

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

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

buildscript {
   repositories {
       // ...
   }

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

After this my app finally ran on the android emulator.

The link has a more complete walkthrough if you get stuck.

Also, to note, I did not have to set multiDexEnabled to true.

Greta answered 24/7, 2019 at 16:55 Comment(0)
C
0

In my case the following works

implementation 'com.google.android.gms:play-services-ads:17.2.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-analytics:16.5.0'
implementation 'com.google.firebase:firebase-messaging:18.0.0'

In my app module. The problem was they firebase-analytics latest library, it is not working properly with the other latest libraries.

Charente answered 25/9, 2019 at 12:55 Comment(0)
K
0

Just add this line in app/build.gradle

defaultConfig {
       multiDexEnabled true 
    }
Kalman answered 5/7, 2020 at 8:18 Comment(0)
B
0

Go Unity >> Edit Project settings>>player, look for Minify section and then choose the Proguard option

Boatel answered 9/11, 2020 at 18:47 Comment(0)
O
0

Along with Unable to merge dex I had an error java.lang.OutOfMemoryError: Java heap space when building a project.

In the gradle.properties file I had this commented line:

# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

Uncommenting this line and increasing the heap memory to 3g solved the problem:

org.gradle.jvmargs=-Xmx3g -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Optimum answered 9/4, 2022 at 11:11 Comment(0)
F
-1

Tried all of them before focusing on dependencies.

The below where killers:

//implementation 'org.apache.httpcomponents:httpcore:4.3.1'
//implementation 'org.apache.httpcomponents:httpmime:4.3.1'

Now is working as intended.

Fricassee answered 24/1, 2018 at 22:19 Comment(1)
This should probably be a comment to the answer from @Benefic The duplicate references will make it fail. This response on its own does not offer new insight on this issue. OP has already accepted an answer on this thread so make sure your answer explains why it is different to the others and is of a similar high quality with links to reference material and in-depth explanation. Some of the other answers to this question are really good examples of well structured and referenced posts.Aquifer
C
-3

If you are using

compile ("org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.1")

you should change it to

compile ("org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.1"){
    exclude group:'org.apache.oltu.oauth2' , module: 'org.apache.oltu.oauth2.common'
}

As the client lib already contains the common lib it creates a duplicate class entry which gives an error:

Unable to merge dex

Candlepower answered 12/10, 2017 at 8:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.