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

半腔热情 提交于 2019-11-27 03:43:47

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.
Dhruv Raval

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!