The number of method references in a .dex file cannot exceed 64K.(转)
前言
我一直都知道app里面的方法数是有限制的差不多64000,具体的就未曾考证了
在遇到这个问题之前,一直以为这个一个多么遥远的距离
其实并不是的,稍有不慎这个异常出来了
当前并不是你真的有编写了64k的方法数量了
大部分都是因为包的重复导入,当前就算是真的超过64k的方法,本文也将提出解决方案
当出现这个情况别慌,我们一步一步来
去除重复包
我们项目中常常都会用到几个LIbrary,然而LIbrary里面的build.gradle和我们app的build.gradle引用了相同类型不同版本的包,来张图给大家看看,方便理解
其中的V4包和annotations包引用了两个不同的版本,增加方法数量的同时也增加了apk包的大小
一般出现The number of method references in a .dex file cannot exceed 64K.先看External Libraries里面是否有大量的重复包,如果有把版本都设置成一致的基本能解决这个异常
如果还有是有的话,可能是项目本身就比较大,也大量的使用了第三方框架等等
分割 Dex 文件解决方法限制
首先app的 build.gradle 中
(1)在dependencies 中添加
compile 'com.android.support:multidex:1.0.1'
(2)在 defaultConfig 中添加
multiDexEnabled true
比如
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "XXXXXX"
minSdkVersion 11
targetSdkVersion 23
versionCode 29
versionName "2.66"
multiDexEnabled true
}
buildType{
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
.......
com.android.support:multidex:1.0.1'
}
(3)在 AndroidManifest.xml 中的 application 标签中添加
1<?xml version="1.0" encoding="utf-8"?>2
<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>
如果你的应用程序继承 Application , 那么你需要重写Application attachBaseContext方法
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this) ;
}
这样的话就可以和64K说拜拜了
转自:http://www.jianshu.com/p/f68b0b070c31
The number of method references in a .dex file cannot exceed 64K.(转)的更多相关文章
- Android工程方法数超过64k,The number of method references in a .dex file cannot exceed 64K.
最近将一个老的Eclipse项目转到Android Studio后,用gradle添加了几个依赖,项目可以make,但是一旦run就报错 Error:The number of method refe ...
- flutter踩坑小记:The number of method references in a .dex file cannot exceed 64K.
The number of method references in a .dex file cannot exceed 64K. 这句话的意思翻译出来是:.dex文件中的方法引用数不能超过64K. ...
- Android开发 Error:The number of method references in a .dex file cannot exceed 64K.
在Android系统中,一个App的所有代码都在一个Dex文件里面.Dex是一个类似Jar的存储了多有Java编译字节码的归档文件.因为Android系统使用Dalvik虚拟机,所以需要把使用Java ...
- react-native安卓运行报错:The number of method references in a .dex file cannot exceed 64K.
错误原因:App里面方法数超过64K解决方法:在android/app/build.gradle中添加implementation 'com.android.support:multidex:1.0. ...
- 如何处理 android 方法总数超过 65536 . the number of method references in a .dex file exceed 64k
一:问题描述: 应用中的Dex 文件方法数超过了最大值65536的上限,简单来说,应用爆棚了. 二.解决方案: 方案1:使用插件化框架 比如: https://github.com ...
- Atitit java方法引用(Method References) 与c#委托与脚本语言js的函数指针
Atitit java方法引用(Method References) 与c#委托与脚本语言js的函数指针 1.1. java方法引用(Method References) 与c#委托与脚本语言js ...
- 在Android项目中启用Java 8的部分特性--Lambda & Method References
Android N发布时同时发布了一个新的编译工具Jack(AS2.1+支持),基于Jack我们可以使用Java 8 的部分特性,在低版本机器上能使用的更少,同时Jack也有诸多不完善,工具链的改变难 ...
- Lambda方法推导(method references)
在上一篇[http://www.cnblogs.com/webor2006/p/7707281.html]中提到了方法推导的东东: 这里说细的学习一下它,下面走起! Method references ...
- Error: Cannot fit requested classes in a single dex file (# methods: 149346 > 65536)
引用第三方库的jar文件,都有可能会触发这个错误.解决方案如下: 参考<[Android]Cannot fit requested classes in a single dex file. T ...
随机推荐
- IIS w3wp对应的应用程序
IIS7以前我們用IISApp查看IIS哪些服務已啟動,但在IIS7已經不適用了,新語法是appcmd.exe list wp.你可以在%windir%\system32\inetsrv\底下找到ap ...
- 阿里云SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
如果是阿里云的服务器 SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in ...
- nine
[拉肚子] 1.原因:消化不良.不良刺激.进食不当的食物/病毒 2.调理: 消化不良引起的:妈咪爱:山药粥:少食多餐 不良刺激引起的:不要受惊受凉过热
- impala 和 kudu 小记
1. impala(官网) 实时交互SQL大数据查询工具 它提供SQL语义,能查询存储在Hadoop的HDFS和HBase中的PB级大数据. Impala的最大特点也是最大卖点就是它的快速. Impa ...
- spark rdd 宽窄依赖理解
== 转载 == http://blog.csdn.net/houmou/article/details/52531205 Spark中RDD的高效与DAG图有着莫大的关系,在DAG调度中需要对计算过 ...
- 【4-1】js函数、事件、补充知识
一.函数操作 (一)字符串操作: (1)变量名.toLowerCase():--转小写 toUpperCase():----转大写 (2)变量名.substring(索引,截取到位数);--- ...
- JMeter之Ramp-up Period(in seconds)说明
Ramp-up Period(in seconds) [1]决定多长时间启动所有线程.如果使用10个线程,ramp-up period是100秒,那么JMeter用100秒使所有10个线程启动并运行. ...
- LabelFunction 允许在显示数据以前进行处理
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- jeecg好用吗,看看大家的评价
大家都会有个疑问,jeecg好用吗? 看看大家的评价
- Java,AWTUtilities,eclipse报编译错误:Access restriction: The type 'AWTUtilities' is not API (restriction on required library 'C:\Program Files\Java\jre7\lib\rt.jar')
[场景]调用com.sun.awt.AWTUtilities时,eclipse提示编译错误: Access restriction: The type 'AWTUtilities' is not AP ...