Android 方法数超出 65536限制的解决方法
来源:互联网 发布:建行网络培训系统 编辑:程序博客网 时间:2024/06/14 07:37
错误原因
有时用户集成完 TuSDK 之后会报如下形式的错误:
UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536
或是
trouble writing output: Too many field references: 131000; max is 65536. You may try using --multi-dex option.
这是因为项目中引用了太多的方法导致打包时 Dalvik Executable (DEX)
文件中的方法数超过了 65536
的限制引起的。
解决方法
Android Studio 允许用户通过 Gradle 的设置来使用多个 DEX
文件,这样每个文件中的方法数就会减少,也就可以绕过这个限制,该方法分为两步进行:
修改 build.gradle 文件
修改项目的 build.gradle
文件启用 MultiDex
并包含 MultiDex
库:
android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { ... minSdkVersion 14 targetSdkVersion 21 ... // Enabling multidex support. multiDexEnabled true } ...}dependencies { compile 'com.android.support:multidex:1.0.0'}
修改 manifest 文件
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.multidex.myapplication"> <application ... android:name="android.support.multidex.MultiDexApplication"> ... </application></manifest>
如果用户不想在 manifest 文件中将 MultiDexApplication 指定为全局 Application,而是想继续使用原先指定的 Application, 则可以在全局 Application 中重写 attachBaseContext()
方法,并加上 MultiDex.install(this)
,如下:
@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this);}
阅读全文
1 0
- Android 方法数超出 65536限制的解决方法
- Android 方法数超出 65536限制的解决方法
- Android 解决Dex超出方法数的限制问题
- Android解决Dex超出方法数限制的问题
- Android 多分包,方法数超出 65536 限制
- Android 使用android-support-multidex解决Dex超出方法数65536的限制问题
- Android 使用android-support-multidex解决Dex超出方法数的限制问题
- Android 使用android-support-multidex解决Dex超出方法数的限制问题
- Android 使用android-support-multidex解决Dex超出方法数的限制问题
- Android 使用android-support-multidex解决Dex超出方法数的限制问题,
- Android——使用android-support-multidex解决Dex超出方法数的限制问题
- Android 使用android-support-multidex解决Dex超出方法数的限制问题
- Android 解决65535的限制 使用android-support-multidex解决Dex超出方法数的限制问题
- android MultiDex multidex原理下超出方法数的限制问题(三)
- 用android-support-multidex解决Dex超出方法数的限制问题
- Android方法数超出限定的解决方案
- 方法数超出64K限制错误
- Android 使用android-support-multidex解决Dex超出方法数的限制问题,让你的应用不再爆棚
- [RK3288][Android6.0] Audio中的混音过程小结
- Linux_Kafka 安装笔记
- vue js 的生命周期和钩子函数
- 集合总结笔记——ArrayList/LinkedList
- SOA开发-02 两个4层架构规范
- Android 方法数超出 65536限制的解决方法
- react-router 从 v2/v3 to v4 迁移
- Tensorflow padding 大小转换公式
- python与自然语言处理(五):中文文本词云
- Java单元测试工具:JUnit4(三)——JUnit详解之运行流程及常用注解
- asp.net 全局sql注入处理 sql关键字过滤 global过滤sql
- EASYUI SPringMVC增删改查的前台页面
- Guava中的TypeToken,解决泛型运行时类型擦除的问题
- Spring-Session分布式集群会话管理