Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 743
Pardeep Kr Avatar asked Apr 28 '16 10:04

Pardeep Kr


3 Answers

For ANDROID STUDIO... Enable Instant Run

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

Hope it helps

like image 122
dianakarenms Avatar answered Oct 16 '22 10:10

dianakarenms


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
like image 8
eoinzy Avatar answered Oct 16 '22 09:10

eoinzy


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'

like image 6
SHS Avatar answered Oct 16 '22 11:10

SHS