Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
来源:互联网 发布:削下颌骨 知乎 编辑:程序博客网 时间:2024/05/22 08:10
前言
我一直都知道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说拜拜了
作者:lance_小超
链接:http://www.jianshu.com/p/f68b0b070c31
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
阅读全文
0 0
- Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
- Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
- Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
- Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
- Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
- Android开发 Error:The number of method references in a .dex file cannot exceed 64K.
- The number of method references in a .dex file cannot exceed 64K. Error 解决方案
- 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. 解决方案
- 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 问题解决
- Error:The number of method references in a .dex file cannot exceed 64K.
- Android studio 报Error:The number of method references in a .dex file cannot exceed 64K错误
- The number of method references in a .dex file cannot exceed 64K
- 解决 The number of method references in a .dex file cannot exceed 64K
- The number of method references in a .dex file cannot exceed 64K.
- 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. Learn how to resolve this
- 【秒懂】号称最为简明实用的Django上手教程(下)
- 基于开源C++的QGIS二次开发学习(一)——属性拷贝
- 2017-08-25阿里校招笔试题---菜鸟仓库
- window10 python 安装 pygame
- 记 2017年初 美国游(图海、史诗级长文预警)
- Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
- iOS-多线程之NSOperation实例和理解
- 解决360/chrome浏览器打开Axure生成的html文件需要安装axure扩展的问题
- [LWIP学习]--tcpip_input,tcpip_inpkt,tcpip_thread函数分析(协议栈入口)
- Java入门基础值数据类型
- Js时间戳毫秒数转日期格式化
- Maven安装及环境变量配置
- Java经典算法题(二)
- 在CentOS系统中安装字体