且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用新的 Android Multidex 支持库启用多索引

更新时间:2023-11-17 18:48:46

Android 5.0(API 级别 21)及更高版本使用支持多索引的 ART.因此,如果您的 minSdkVersion 为 21 或更高,则不需要 multidex 支持库.

Android 5.0 (API level 21) and higher uses ART which supports multidexing. Therefore, if your minSdkVersion is 21 or higher, the multidex support library is not needed.

修改你的build.gradle:

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true
         }
}

dependencies {
    implementation 'com.android.support:multidex:1.0.3'
}

如果您正在运行单元测试,您需要将其包含在您的 Application 类中:

If you are running unit tests, you will want to include this in your Application class:

public class YouApplication extends Application {

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}

或者只是让你的 application 类扩展 MultiDexApplication

Or just make your application class extend MultiDexApplication

public class Application extends MultiDexApplication {

}

有关详细信息,此是一个很好的指南.