您的位置:首页 > 移动开发 > Android开发

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

2015-09-18 19:53 429 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: