Android breakthrough 64K limit

1. Add dependence

android{
    defaultConfig{
        ...
        multiDexEnabled true
        ...
    }
}
dependencies{
    compile 'com.android.support:multidex:1.0.0'
}

2. If the project did not achieve a custom Application class, you only need to use the AndroidManifest.xml file MultiDexApplication to replace Application

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.xxx.xxx">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication"
        ...
    </application>
</manifest>

3. If the project has achieved a custom Application class, you can inherit it MultiDexApplication

public class MyApplication extends MultiDexApplication{
    @Override
    public void onCreate(){
        super.onCreate();
    }
}

4. If the project has achieved a custom Application class, and do not want or can not modify its parent class, you can initialize by diarrhea attachBaseContext method and MultiDex

public class MyApplication extends BaseApplication{
    @Override
    protected void attachBaseContext(Context base){
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
}

Guess you like

Origin www.cnblogs.com/heweiquan/p/10973142.html