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 ...
随机推荐
- Ubuntu 下安装 Swoole
环境:Ubuntu16.04 apt-get update apa-get install apache2 php php-pear php-dev mysql-server gcc apache2 ...
- linux 任务调度
crontab 定时任务 -e 编辑 -l 查看 -r 删除 参数 * * * * * 分钟 小时 天数 月 星期几
- VC开发中一些问题的解决
(1) MFC:在视频窗口上显示一个图片: 使用button显示图片的话,鼠标点击好图片(按钮)上,窗口无法响应. 应该使用一个static静态控件来显示,这样不会妨碍视频窗口对鼠标消息的响应. (2 ...
- Django--URL(路由层)
一.django 静态文件配置 在配置文件中settings.py STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR ...
- C#--构造函数的理解
说白了构造函数就是用来初始化类的数据成员{因为C#语言具有类型安全的特质-->不能使用没有初始化的变量)} 在这里引用一下别人的总结,我觉得挺好的: 构造函数是一种特殊的成员函数,它主要用于为对 ...
- 使用Docker容器的十大误区
转自:http://www.dockone.io/article/1264 对于用户来说,可能一开始在不了解的情况下会对容器报以拒绝的态度,但是在尝到容器的甜头.体验到它的强大性能之后,相信大家最终是 ...
- harbor仓库镜像的删除
harbor仓库镜像的删除 刚开始自己摸索了下,直接webui界面删除后,发现仓库空间未释放 上传之前仓库空间占用为 上传之后仓库空间占用为 在webui界面上删除镜像后 查看大小 依旧为286m,到 ...
- 如何使用JDBC连接Mysql数据库
//java类名BaseDaopublic class BaseDao { private Connection conn = null; // 声明Connection对象,Connectio ...
- 【原创】逆向练习(CrackMe)
Write Up 登录的两个方法 方法1.用IDA分析 新版测试题.exe.在Strings Window中查找有一定意义的串. 从上面的窗口中,发现了CyberSwat和passwordisme这两 ...
- css3的2D和3D的转换
一:2D转换: 通过 CSS3 transform转换,我们能够对元素进行移动.缩放.转动.拉长或拉伸. 2D移动:translate().使用translate()函数,你可以把元素从原来的位置移 ...