如何使用新的 Android Multidex 支持库启用多索引 [英] How to enable multidexing with the new Android Multidex support library
问题描述
我想使用新的 Multidex 支持库来打破我的一个应用程序的方法限制.
I want to use the new Multidex support library to break the method limit for one of my apps.
在 Android Lollipop 中,Google 引入了一个 multidex 支持库,可以轻松实现 multidex.
With Android Lollipop Google introduced a multidex support library that makes it easy to multidex.
使用该库以及构建支持多索引的应用需要哪些步骤?
What steps are needed to use this library and to build my app with multidex support?
推荐答案
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 {
}
有关详细信息,此是一个很好的指南.
这篇关于如何使用新的 Android Multidex 支持库启用多索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!