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); 
   } 
}


(如果你编译的时候报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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值