Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
来源:互联网 发布:50cms内容发布系统 编辑:程序博客网 时间:2024/06/08 07:19
前言
我一直都知道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
- 17 H5里的i2c控制器驱动
- Python安装模块出错(ImportError: No module named setuptools)解决方法
- Android APP终极瘦身指南
- VBO usage标示符
- springmvc运行原理
- Android开发 Error(建议收藏下来以备不时之需):The number of method references in a .dex file cannot exceed 64K.
- Ubuntu16.04LTS 安装CUDA9.0
- sparksql减少输出数据中的小文件数量
- Mac High Sierra 中不能改变/usr/local的拥有者
- ubuntu允许root登录ftp服务器
- 怎样给自己的网站加一个网址,然后让别人访问呢?
- java线程池
- react状态提升 父子组件交互
- 我的Android征途