Android Studio方法总数超过64K报错Error:The number of method references in a .dex file cannot exceed 64K.
记录开发中的点滴
Error:The number of method references in a .dex file cannot exceed 64K.
上面的错误显示一个共同的数字:65536。这个数字是重要的,它代表了引用的总数,可以在单个调用的代码Dalvik可执行(Dex)字节码文件。如果你的Android应用发生这个错误,恭喜你,你的代码已经达到了一定的量!本文解释了如何解决这个限制并继续构建应用程序。
关于64 k引用限制
Android应用程序(APK)在Dalvik可执行文件的形式包含可执行的字节码文件(DEX)文件,其中包含已编译的代码来运行你的应用程序。Dalvik可执行规格限制一个Dex文件包含65536个方法:包括Android框架方法、Library方法的总数、和你自己的代码方法总数。因为65536等于64×1024,这一限制被称为“64k引用限制”。
这个极限就要求我们配置应用程序的构建过程,需要生成多个DEX文件,所以称为multidex 配置。
1.问题描述
Error:The number of method references in a .dex file cannot exceed 64K.
Error:Execution failed for task ':app:transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_77\bin\java.exe'' finished with non-zero exit value 2‘’?
2.解决方案
方案1:使用插件化框架 比如: https://github.com/singwhatiwanna/dynamic-load-apk
方案2:分割Dex
(1)在model添加依赖
implementation 'com.android.support:multidex:1.0.1'
(2)在 model 中的defaultConfig 下添加
multiDexEnabled true
(3)自定义MyApplication继承MultiDexApplication,重写attachBaseContext函数
@Override
protected void attachBaseContext(Context base) {super.attachBaseContext(base);MultiDex.install(this);
}
(4)在 AndroidManifest.xml 中的 application 标签中添加
如对此有疑问,请联系qq1164688204。
推荐Android开源项目
项目功能介绍:RxJava2和Retrofit2项目,添加自动管理token功能,添加RxJava2生命周期管理,使用App架构设计是MVP模式和MVVM模式,同时使用组件化,部分代码使用Kotlin,此项目持续维护中。
项目地址:https://gitee.com/urasaki/RxJava2AndRetrofit2
Android Studio方法总数超过64K报错Error:The number of method references in a .dex file cannot exceed 64K.相关推荐
- 方法超出 android,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 ...
- Android studio: The number of method references in a .dex file cannot exceed 64K. Learn how to resol
报错log: Error:The number of method references in a .dex file cannot exceed 64K. Learn how to resolve ...
- AndroidStudio:The number of method references in a .dex file cannot exceed 64K错误
在AndroidStudio中出现下面的错误提示: Error:The number of method references in a .dex file cannot exceed 64K. Le ...
- Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
前言 我一直都知道app里面的方法数是有限制的差不多64000,具体的就未曾考证了 在遇到这个问题之前,一直以为这个一个多么遥远的距离 其实并不是的,稍有不慎这个异常出来了 当前并不是你真的有编写了6 ...
- The number of method references in a .dex file cannot exceed 64K. Error 解决方案
我们都知道app里面的方法数是有限制的差不多64000个,具体就为曾考证了 在遇到这个问题之前,一直以为这是一件多么遥远的事情,其实并不是的,稍有不慎这个异常出来了 也有可能并不是你真的有编写了64k ...
- 解决The number of method references in a .dex file cannot exceed 64K的问题
需要分包build只需要 在build.gradle defaultConfig中加入 multiDexEnabled true defaultConfig {multiDexEnabled true ...
- 如何处理 android 方法总数超过 65536 . the number of method references in a .dex file exceed 64k
一:问题描述: 应用中的Dex 文件方法数超过了最大值65536的上限,简单来说,应用爆棚了. 二.解决方案: 方案1:使用插件化框架 比如: https://github.com ...
- 【Android开发遇错】Android studio 添加jar后编译报错Error converting bytecode to dex: Cause: Dex cannot pars
** 添加了一个mysql-connector-java-5.1.38-bin.jar然后编译就报错了 ** 错误信息如下: Error:Error converting bytecode to de ...
- Android当方法总数超过64K时(Android Studio)
1. 问题描述 Error:The number of method references in a .dex file cannot exceed 64K. Error:Execution fail ...
- android apt最新版本,解决Android studio 2.3升级到Android studio 3.0 后apt报错问题
解决Android studio 2.3升级到Android studio 3.0 后apt报错问题 发布时间:2020-09-16 19:59:42 来源:脚本之家 阅读:62 作者:哈特中尉 1. ...
最新文章
- 分类讨论 ---- 2021 icpc 沈阳 L Linear Fractional Transformation (思维题)
- 第一代计算机到第四代计算机基本知识,[Ch01_计算机系统基本知识.ppt
- 在javascript中,如何判断一个被多次encode 的url 已经被decode到原来的格式?
- java怎么打印进制,java编程思维_007打印二进制,八进制,十六进制
- 关于文件系统权限的管理
- 召回粗排精排-级联漏斗(下)
- QuickLook 空格键预览文件工具
- 导数/微分/积分的区别
- 基于C#的简单聊天软件开发
- 计算机配色与人工配色原则,计算机配色的理论与实践研究
- network secruity studay day2
- 随手练——小米OJ 高弗雷勋爵
- 中英文说明书丨CalBioreagents ACTH N端单克隆抗体
- PCB学习(一)——立创EDA边框设置
- maven打包报错Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.5.2.RELEASE:repa
- Quartz——简介和使用
- 写代码到底应该买什么键盘?
- 【078】比才歌剧《卡门》序曲
- 163电子邮箱注册登录入口是?企业邮箱和163邮箱有什么区别?
- C++][基础知识 5] 虚函数
热门文章
- 洛谷 2184 贪婪大陆
- 【新书推荐】【2019.06】大局观从何而来
- Period 、Duration常用方法使用与介绍
- Raspberry-Pi-PICO系列--第七篇 创建自己的工程
- php 中%3cspan%3e,vue实战(4)——网站统计之——友盟百度统计
- eclipse使用技巧——备注格式的定义与模板
- 流程管理对企业有何价值?如何做好企业流程管理?
- 运算放大器单电源设计
- 今日头条的排名算法_今日头条旗下悟空问答的排名算法规则
- 专用计算机的运行速度,WIN10专业版下电脑运行速度慢多个解决技巧