1.在app的 build.gradle 中
dependencies {
...
compile 'com.android.support:multidex:1.0.0'//这行
}
defaultConfig {
applicationId "com.dex.test"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true//这行
}
2.如果自定义了一个MyApplication继承了Application,那么现在需要让它继承MultiDexApplication并且重写attachBaseContext方法
在 AndroidManifest.xml 中的 application 标签中添加 :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.vieboo.test">
<application
...
android:name=".MyApplication">
//如果没有自定义MyApplication,那么写下面这句
//android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
/**
* 分割 Dex 支持
* @param base
*/
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}