使用MultiDex解决65535限制问题
来源:互联网 发布:手机版施工软件 编辑:程序博客网 时间:2024/05/16 10:38
版权声明:本文为[qiufengyi002]的原创文章,转载请注明出处,否则禁止转载。
项目中使用了,但是一直不清楚是怎么做的,简单了解了下,知道了具体的流程
第一步,在app module下的build.gradle里允许使用
apply plugin: 'com.android.application'android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "*****************" minSdkVersion 11 targetSdkVersion 19 versionCode 1 versionName "1.0.0" multiDexEnabled true }
第二步,在app module下的build.gradle里添加包引用,并且让自己的Application继承android.support.MultiDex.MultiDexApplication
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.0'
}
编译的时候会自动在external Libraries下下载的
第三步,为了防止出现主dex包过大的情况,导致NoClassDefFoundError错误的出现,需要在 app module
下创建 multidex.keep
文件,并在其中列出那些 class,以便让编译器知道在 main dex 文件中要保持哪些 class。
生成multidex.keep的方法为:
在app module下的build.gradle中添加如下代码
afterEvaluate { tasks.matching { it.name.startsWith('dex') }.each { dx -> if (dx.additionalParameters == null) { dx.additionalParameters = [] } //允许生成多个dex文件 dx.additionalParameters += '--multi-dex' // enable multidex // 设置multidex.keep文件中class为第一个dex文件中包含的class,如果没有下一项设置此项无作用 dx.additionalParameters += "--main-dex-list=$projectDir/class-list.txt".toString() //此项添加后第一个classes.dex文件只能包含-main-dex-list列表中class dx.additionalParameters += '--minimal-main-dex' }}然后clean再rebuild项目,然后找到
build/intermediates/multi-dex/xxx
里 maindexlist.txt
文件(如果找不到相关目录,可能需要你同步后 rebuild
项目才能生成,如果还是没有,那就跑项目或者打包吧,虽然会报错),复制里面的内容到 module
根目录下 multidex.keep
文件中(没有则先创建此文件)。第四步、把第三步中在app module中添加的代码删掉,加上如下代码
def patchKeepSpecs() { def taskClass = "com.android.build.gradle.internal.tasks.multidex.CreateManifestKeepList"; def clazz = this.class.classLoader.loadClass(taskClass) def keepSpecsField = clazz.getDeclaredField("KEEP_SPECS") keepSpecsField.setAccessible(true) def keepSpecsMap = (Map) keepSpecsField.get(null) if (keepSpecsMap.remove("activity") != null) { println "KEEP_SPECS patched: removed 'activity' root" } else { println "Failed to patch KEEP_SPECS: no 'activity' root found" }}patchKeepSpecs()
以上方法是自己总结的,但是因为项目本身已经使用了,所以没有再重复走一遍流程,如果有需要的同学,可以看下,看是否成功。
0 0
- 使用MultiDex解决65535限制问题
- Android 解决65535的限制 使用android-support-multidex解决Dex超出方法数的限制问题
- MultiDex解决64K限制的问题
- 使用MultiDex 解决64K限制
- Android 解决65535的限制 使用android-support-multidex解决Dex超出方法数的限制问题,让你的应用不再爆棚
- Android 解决65535的限制 使用android-support-multidex解决Dex超出方法数的限制问题,让你的应用不再爆棚
- Android 解决65535的限制 使用android-support-multidex解决Dex超出方法数的限制问题,让你的应用不再爆棚
- Android 解决65535的限制 使用android-support-multidex解决Dex超出方法数的限制问题,让你的应用不再爆棚
- Android 解决65535的限制 使用android-support-multidex解决Dex超出方法数的限制问题,让你的应用不再爆棚
- Android 使用android-support-multidex解决Dex超出方法数的限制问题
- Android 使用android-support-multidex解决Dex超出方法数的限制问题
- Android 使用android-support-multidex解决Dex超出方法数的限制问题
- Android 使用android-support-multidex解决Dex超出方法数65536的限制问题
- Android 使用android-support-multidex解决Dex超出方法数的限制问题,
- Android——使用android-support-multidex解决Dex超出方法数的限制问题
- Android 使用android-support-multidex解决Dex超出方法数的限制问题
- Android 项目开发填坑记 - 使用 MultiDex 解决 64K 限制
- Android 项目开发填坑记 - 使用 MultiDex 解决 64K 限制
- QT中的setGeometry (9, 9, 50, 25) 四个参数分别是指什么?
- LeetCode#62. Unique Paths
- poj3468 A Simple Problem with Integers(用线段树和树状数组实现)
- 九、FatMouse' Trade
- 理解进程调度时机跟踪分析进程调度与进程切换的过程
- 使用MultiDex解决65535限制问题
- STL----iterator 迭代器
- More is Less——卷积网络加速
- Java类的访问权限
- RecyclerView自定义分割线————列表分割线
- 题目1057:众数
- Java扑克牌小游戏
- eclipse对比idea快捷键
- ViewPager设置预加载界面个数