使用 MultiDex 解决 64K 限制

第一步:添加依赖

dependencies {
  compile 'com.android.support:multidex:1.0.1'
}

第二步:开启分包设置

defaultConfig { 
  ... 
   multiDexEnabled true 
  ... 
}Gradle

第三步:

存在自定义Application

如存在自定义Application,则在自定义Application的onCreate方法中。调用

@Override
    public void onCreate() {
        super.onCreate();
        MultiDex.install(this);
    }

然后在AndroidManifest.xml中

//自定义的Application
<application
       android:name="xxx.xxx.xxx.DemoApplication
       android:allowBackup="true"
       android:icon="@mipmap/ic_launcher"
       android:label="@string/app_name"
       android:roundIcon="@mipmap/ic_launcher_round"
       android:supportsRtl="true"
       android:theme="@style/AppTheme">
     ....
</application>

不存在自定义Application

如果没有自定义的Application则直接使用以下方式

<application
       android:name="android.support.multidex.MultiDexApplication"
       android:allowBackup="true"
       android:icon="@mipmap/ic_launcher"
       android:label="@string/app_name"
       android:roundIcon="@mipmap/ic_launcher_round"
       android:supportsRtl="true"
       android:theme="@style/AppTheme">
     ....
</application>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,909评论 25 708
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,845评论 18 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,926评论 6 342
  • 我们家有兄弟姐妹八个孩子,小弟六岁时溺亡,还有我们七个: 大姐、哥哥、二姐、我、大妹妹、弟弟,最小的是五妹。 大姐...
    岳家屯阅读 1,255评论 0 0
  • 今日日期: 2017年11月3日 今日开心事: 要周末放假了! 今日介绍时间管理: 1.等量 1个番茄=25分钟 ...
    China_first阅读 221评论 1 0