Unable to merge dex Unable to merge dex android android

Unable to merge dex


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

app/build.gradle:

android {    defaultConfig {       multiDexEnabled true    }}


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:

  1. clean
  2. rebuild


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.