[android] Unable to merge dex

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

This question is related to android dex android-studio-3.0

The answer is


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!


I also had the problem.

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


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'
          }
      }
}

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.


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: http://stackoverflow.com/a/35169716/530047

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.


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'
        }
    }
}

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)

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.


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.


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.


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


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.


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/**')
}

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


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 !


Just add below in build.gradle,

defaultConfig { multiDexEnabled true }


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.


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


Just add this line in app/build.gradle

defaultConfig {
       multiDexEnabled true 
    }

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.


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:


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


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'

./gradlew :app:assembleStubLiveDebug -debug -stacktrace

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


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.


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

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')
 }

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


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

app/build.gradle:

android {
    defaultConfig {
       multiDexEnabled true
    }
}

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

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.


[ 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


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


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.


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.


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.

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'
     }
   }
  }
}

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.


    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


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.


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


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


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.


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

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

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.


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

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

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


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.


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.


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


    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


  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.


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


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'

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.


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.


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.


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.


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


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 **/
}

add commands below:

android {
...

    dexOptions {

        jumboMode true
        javaMaxHeapSize "4g"

    }
}

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

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


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to dex

Unable to merge dex Android dex gives a BufferOverflowException when building Unable to execute dex: method ID not in [0, 0xffff]: 65536 How to extract code of .apk file which is not working? Unable to execute dex: Multiple dex files define Lcom/myapp/R$array; What are .dex files in Android? Is it possible to decompile an Android .apk file? decompiling DEX into Java sourcecode

Examples related to android-studio-3.0

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve Failed linking file resources Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project Android Studio 3.0 Execution failed for task: unable to merge dex Android studio 3.0: Unable to resolve dependency for :app@dexOptions/compileClasspath': Could not resolve project :animators Unable to merge dex Unsupported method: BaseConfig.getApplicationIdSuffix() Android Room - simple select query - Cannot access database on the main thread Android emulator not able to access the internet