6

I have and android project. When i import it to eclipse . it works fine . But when i imported it to Android studio its giving :-

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

error while building . Is it even possible for a project to behave diffrently in eclipse and Android Studio . In both case (Yes / No) , how do i resolve it

I have checked my build.gradle file for dependencies . All the dependencies are same as what i am using in eclipse.

3 Answers 3

9

For ANDROID STUDIO... Enable Instant Run

In File->Preferences->Build, Execution, Deployment->Instant Run-> Check Enable Instant run for hot swap...

Hope it helps

2
  • 1
    Thanks - Bang on!!! I just created a sample app and i was surprised with the error as it was just a tiny app i could not believe it would cross upper limit of Methods of 65536.
    – Ash
    Feb 5, 2017 at 9:22
  • This! I knew I did not have the issues solved in the accepted answer since the project would run on my co-worker's machine. This solution worked perfectly.
    – arneson
    Mar 14, 2017 at 11:52
8

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

The most common cause of this is using the full google play services library, instead of just the subset you need, eg design, cardview, maps etc.

If this is not the case, then use the multidex library, which enables a bigger limit. See here: http://developer.android.com/tools/support-library/features.html#multidex

Basically just this in gradle:

com.android.support:multidex:1.0.0
3
  • i was using this line in my dependencies , when i got the this error. "compile 'com.google.android.gms:play-services:+' " But as you mentioned play services is the reason. So i removed it and now i am using " compile files('libs/google-play-services_lib.jar') " like this . I have added google-play-services_lib.jar in the libs folder of my project . But now i am getting below error:- " No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version') "
    – Pardeep Kr
    Apr 28, 2016 at 11:08
  • 1
    no, forget about the .jar and go back to using gradle. What I meant was that compile 'com.google.android.gms:play-services:+' contains all of the play service library, but you should only use the ones you need, eg compile 'com.google.android.gms:play-services-maps:8.4.0' for Google Maps, or compile 'com.google.android.gms:play-services-location:8.4.0' for Location.
    – eoinzy
    Apr 28, 2016 at 11:39
  • 1
    Another suggestion is to get rid of unnecessary plugins in your project. At least this solved my problem in my project with exactly the same error message. By removing unnecesary plugins, you effectively reduce the number of methods included in your app.
    – J D
    Feb 1, 2017 at 22:00
6

My problem was resolved by adding "multiDexEnabled true" as following in Module build.gradle.

android {
    ...
    defaultConfig {
        ...
        multiDexEnabled true

Update

With the above code, I was able to build and run on debug devices (below 'marshmallow' version), but on 'marshmallow' devices, I found the following error.

:6: error: package android.support.multidex does not exist import android.support.multidex.MultiDexApplication;

To resolve I have to use following in 'module' build.gradle of project.

compile 'com.android.support:multidex:1.0.1'

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.