Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After update of AS to 1.0, getting "method ID not in [0, 0xffff]: 65536" error in project

I updated Android Studio to the latest version, and let it "fix the project" and the like - but now my project does not compile, gives me

 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    D:\VGA\AndroidStudio\sdk\build-tools\21.1.1\dx.bat --dex --no-optimize --output D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\dex\debug --input-list=D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
    2
Output:

    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
        at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
        at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
        at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
        at com.android.dx.command.dexer.Main.run(Main.java:245)
        at com.android.dx.command.dexer.Main.main(Main.java:214)
        at com.android.dx.command.Main.main(Main.java:106)

However, this isn't resolved by just multidexing, because when I added this:

defaultConfig {
    ...
    multiDexEnabled = true
}

This happens

D:\VGA\AndroidStudio\sdk\build-tools\21.1.1\dx.bat --dex --no-optimize --multi-dex --main-dex-list D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\multi-dex\debug\maindexlist.txt --output D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\dex\debug --input-list=D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\tmp\dex\debug\inputList.txt

Error Code: 3 Output:

UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: GC overhead limit exceeded
    at com.android.dx.cf.code.ConcreteMethod.makeSourcePosistion(ConcreteMethod.java:254)
    at com.android.dx.cf.code.RopperMachine.run(RopperMachine.java:306)
    at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:612)
    at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:367)
    at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94)
    at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:787)
    at com.android.dx.cf.code.Ropper.doit(Ropper.java:742)
    at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
    at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:280)
    at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
    at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
    at com.android.dx.command.dexer.Main.processClass(Main.java:729)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
    at com.android.dx.command.dexer.Main.access$300(Main.java:82)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
    at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
    at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
    at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
    at com.android.dx.command.dexer.Main.processOne(Main.java:632)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:505)
    at com.android.dx.command.dexer.Main.runMultiDex(Main.java:332)
    at com.android.dx.command.dexer.Main.run(Main.java:243)
    at com.android.dx.command.dexer.Main.main(Main.java:214)
    at com.android.dx.command.Main.main(Main.java:106)

I tried changing the build tools to latest

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

Because by default it changed to 20.0.0 which seemed to use the SDK for 4.4W, but this didn't fix my problem.

Does anyone know what could be wrong here?

EDIT:

Changing the build tools or the compile SDK did not fix the problem.

Turning the app into a multi-dex project and also adding the following

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        ...
        multiDexEnabled true
    }

...
    dexOptions {
        incremental true
        javaMaxHeapSize "4g"
    }
}

Fixed the build process, however this still seems to be just a "treatment" but not a fix to the problem.

I am not sure if this is related, but this is my dependency list:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:appcompat-v7:21.0.2'
    compile 'com.squareup:otto:1.3.5'
    compile 'com.squareup.picasso:picasso:2.4.0'
    compile 'com.squareup.retrofit:retrofit:1.7.1'
    compile 'com.jakewharton:butterknife:6.0.0'
    compile 'com.madgag.spongycastle:core:1.51.0.0'
    compile 'com.madgag.spongycastle:prov:1.51.0.0'
    compile 'com.madgag.spongycastle:pkix:1.51.0.0'
    compile 'com.google.code.gson:gson:2.3'
    compile 'commons-io:commons-io:2.4'
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
    compile 'com.squareup.dagger:dagger:1.2.2'
    compile 'com.squareup.dagger:dagger-compiler:1.2.2'
    compile('com.googlecode.json-simple:json-simple:1.1.1') {
        exclude module: 'junit'
    }
    compile 'com.google.android.gms:play-services:6.5.87'
}

The only new dependency since then has been the last line, which I added as per https://developer.android.com/google/gcm/client.html so I don't think that is the source of the problem.

EDIT2:

Yes, it was the source of the problem. As I needed Google Cloud Messaging, I replaced that dependency with the base as per http://developer.android.com/google/play-services/setup.html#split :

compile 'com.google.android.gms:play-services-base:6.5.87'

And it fixed the problem. Thank you for the help.

EDIT3:

As of play services 7.0.0, the GCM is in

compile 'com.google.android.gms:play-services-gcm:7.0.0'

EDIT4:

Play Services updated to 7.3.0. Please keep check of the latest version here: http://developer.android.com/google/play-services/setup.html#split

like image 202
EpicPandaForce Avatar asked Dec 09 '14 10:12

EpicPandaForce


2 Answers

The error means you have reached maximum method count in your app. That does include any libraries that you use for your project.

There are two ways to tackle the issue:

  1. Get rid of any third-party libraries that you don't really need. If you use google play services that might contribute a lot to the method count. Fortunately as of the latest play-services release it is possible to include only parts of the framework.
  2. Use a multi dex setup for your application.
like image 173
Konstantin Burov Avatar answered Nov 19 '22 12:11

Konstantin Burov


I am phasing these problem & in my case used these link to overcome that error successfully..!!!

The DEX 64k limit is not a problem anymore, almost

To sum it up, adding multidex support:

In case of

UNEXPECTED TOP-LEVEL EXCEPTION:

com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 
   at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502) 
   at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277) 
   at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491) 
   at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168) 
   at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) 
   at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) 
   at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302) 
   at com.android.dx.command.dexer.Main.run(Main.java:245) 
   at com.android.dx.command.dexer.Main.main(Main.java:214) 
   at com.android.dx.command.Main.main(Main.java:106)

Google decided to release an official solution for this in the form of the MultiDex Support Library.

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

Then enable multi-dexing by setting the multiDexEnabled flag in the buildType or productFlavor section of your gradle configuration.

defaultConfig { 
   ... 
multiDexEnabled true 
... 
}

Then depending on your project, you have 3 options:

If you haven’t created your own Application class, simply declare android.support.multidex.MultiDexApplication as your application class in AndroidManifest.xml

   .... 
   android:name="android.support.multidex.MultiDexApplication" 
   ... 

If you already have your own Application class, make it extend android.support.multidex.MultiDexApplication instead of android.app.Application

If your Application class is extending some other class and you don’t want to or can’t change it, override attachBaseContext() as shown below:

public class MyApplication extends FooApplication { 
   @Override 
   protected void attachBaseContext(Context base) { 
      super.attachBaseContext(base); 
      MultiDex.install(this); 
   } 
}

Your compilation process might run out of memory. To fix it, set the following dex options in the ‘android’ closure –

dexOptions { 
   incremental true 
   javaMaxHeapSize "4g" 
}

More to know about multidex is here: http://developer.android.com/tools/building/multidex.html

Another link which becomes helping to solve a these error : Referance Link

like image 27
Dhruv Raval Avatar answered Nov 19 '22 13:11

Dhruv Raval