Android 解决“com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536”问题

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.
(设置multiDexEnabled 标签到gradle配置)

defaultConfig { 
   ... 
multiDexEnabled true 
... 
}

Then depending on your project, you have 3 options:

(根据你的工程会有3中情况)
1、(如果你没有自己的Application)
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" 
   ... 


2、(如果你有自己的application,可以将继承Application改成去继承android.support.multidex.MultiDexApplication)
If you already have your own Application class, make it extend android.support.multidex.MultiDexApplication instead of android.app.Application


3、(如果你继承了其他的类,不用改变他,直接覆盖他的attachBaseContext()方法,如下:)
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); 
   } 
}


扫描二维码关注公众号,回复: 3434404 查看本文章
(如果你编译的时候报oom,使用如下的方法)
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" 
}

详细见:

http://stackoverflow.com/questions/27377080/after-update-of-as-to-1-0-getting-method-id-not-in-0-0xffff-65536-error-i

猜你喜欢

转载自blog.csdn.net/gulihui890411/article/details/48551551