62

I use Android Studio to develop an application and I face this error which I have no idea how to solve.

com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]

:app:lintVitalRelease
:app:prePackageMarkerForRelease
:app:transformClassesWithDexForRelease FAILED
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
Information:BUILD FAILED
Information:Total time: 34.783 secs
Information:1 error 
Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
Hassan Ouhadou
  • 621
  • 1
  • 5
  • 5

8 Answers8

122

Try to enable multiDex in build.gradle:

android {

    defaultConfig {
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

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

This article may helpful: DexIndexOverflowException issue after updating to latest appcompat and support library

Community
  • 1
  • 1
xxx
  • 3,315
  • 5
  • 21
  • 40
  • 6
    If the error was caused by adding Google Play services then take a look at this answer instead: http://stackoverflow.com/a/35210195/1340631 – scai Dec 27 '16 at 10:02
  • 1
    my problem was solved by putting dexOptions { javaMaxHeapSize "4g" } – Dansp Jun 28 '17 at 23:54
  • 1
    @DanielPereira. Eventually, the thing we should do is to optimize our code, our application instead of increasing the heap size even though our modern devices' memory today are bigger than that in the past :) – xxx Jun 29 '17 at 03:19
  • @VIRGINSTV, just to put everything to one place: additionally, you need to call MultiDex.install or use MultiDexApplication according to docs https://developer.android.com/studio/build/multidex. And another solution is to change minSdk to 21 where multidex is not needed, there will be no such error – Deepscorn Oct 31 '19 at 14:42
27

Android has a pre-defined upper limit of Methods of 65536.

if you added play services as whole please remove it and add specific ones.

remove compile 'com.google.android.gms:play-services:9.6.1' and then add ex: compile 'com.google.android.gms:play-services-maps:9.6.1' for maps.

https://developers.google.com/android/guides/setup

shows a list of the separate APIs that you can include when compiling your app, and how to describe them in your build.gradle file

vbp
  • 1,157
  • 10
  • 16
  • 1
    That was my issue. I created MapActivity and google added whole bunch of services. Thank you! – Stefano Mtangoo Nov 17 '16 at 10:28
  • 2
    In my case I had set both dependencies `compile 'com.google.android.gms:play-services:10.0.1'`, `compile 'com.google.android.gms:play-services-ads:10.0.1'` *and had to reduce it to* `compile 'com.google.android.gms:play-services-ads:10.0.1'` – Yoraco Gonzales Jan 23 '17 at 22:46
  • 1
    This should be the accepted answer. This worked for me. The others may work but the underlying reason is that a lot of unneeded services are used. – mister270 Apr 28 '17 at 22:00
22

set multiDex in your gradle

defaultConfig {
    // ...
    multiDexEnabled true
}

it's work for me.

Eugene Lezov
  • 722
  • 7
  • 12
7

Best way use individual package under the list of all google services package.

Google Play services API                Description in build.gradle                                       
Google+                                            com.google.android.gms:play-services-plus:11.2.0
Google Account Login                      com.google.android.gms:play-services-auth:11.2.0
Google Actions, Base Client Librarycom.google.android.gms:play-services-base:11.2.0
Google Address                                API com.google.android.gms:play-services-identity:11.2.0
Google Analytics                              com.google.android.gms:play-services-analytics:11.2.0
Google Awareness                          com.google.android.gms:play-services-awareness:11.2.0
Google Cast                                    com.google.android.gms:play-services-cast:11.2.0
Google Cloud Messaging                com.google.android.gms:play-services-gcm:11.2.0
Google Drive                                  com.google.android.gms:play-services-drive:11.2.0
Google Fit                                       com.google.android.gms:play-services-fitness:11.2.0
Google Location and Activity Recognition com.google.android.gms:play-services-location:11.2.0
Google Maps com.google.android.gms:play-services-maps:11.2.0
Google Mobile Ads     com.google.android.gms:play-services-ads:11.2.0
Google Places com.google.android.gms:play-services-places:11.2.0
Mobile Vision com.google.android.gms:play-services-vision:11.2.0
Google Nearby com.google.android.gms:play-services-nearby:11.2.0
Google Panorama Viewer com.google.android.gms:play-services-panorama:11.2.0
Google Play Game services com.google.android.gms:play-services-games:11.2.0
SafetyNet com.google.android.gms:play-services-safetynet:11.2.0
Android Pay com.google.android.gms:play-services-wallet:11.2.0
Android Wear com.google.android.gms:play-services-wearable:11.2.0

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
6
    Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536


solution : inside build.gradle(app)
defaultConfig {
        applicationId "com.rentalhousereviews"
        ------------
        -----------
        multiDexEnabled true  //add this line
    }



dependencies {
compile 'com.android.support:multidex:1.0.1'
}
Kishore Reddy
  • 2,394
  • 1
  • 19
  • 15
5

DexIndexOverflowException is also caused by exceeding 65536 methods. This can easily happen when adding a large library such as Google Play services. See this answer for a solution.

Community
  • 1
  • 1
scai
  • 20,297
  • 4
  • 56
  • 72
2

more than 4 months that i find this error in my projects created by myself i'm losing more than 14 projects with this thing. i'm looking to all places of stackoverflow and other and also the website official of android.developer.multidex extr..... but any method official of google android was solve my issues.

finally i'm trying with the simple change of google play service of Ads. this's the final solution that i'm finding :

  • firstly compile witch i find the error is : compile 'com.google.android.gms:play-services:9.0.2'

  • the change is just to add "-maps" and make sure that your ads it's working perfectly ! compile 'com.google.android.gms:play-services-maps:9.0.2'

the version 9.0.2 can let your minSdkVersion 11 working, as you know the Ads can working only with version 11 and hight !

i'm proud to find the solution and share this simple solution to solve the issue of other persons.

yaszin
  • 33
  • 7
0

Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.

com.android.build.api.transform.TransformException: com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536

Latest version com.android.support:multidex:1.0.3 worked for me!

dependencies {
  compile 'com.android.support:multidex:1.0.3'
}
Trần Hạnh
  • 147
  • 1
  • 10