您的位置:首页 > 移动开发 > Android开发

Android Error:The number of method references in a .dex file cannot exceed 64K.

2017-12-26 17:28 573 查看
在导入Umeng 数据统计和push 后编译正式包出现该问题。

我一直都知道app里面的方法数是有限制的差不多64000,具体的就未曾考证了

在遇到这个问题之前,一直以为这个一个多么遥远的距离

其实并不是的,稍有不慎这个异常出来了

当前并不是你真的有编写了64k的方法数量了

大部分都是因为包的重复导入,当前就算是真的超过64k的方法,本文也将提出解决方案

参考文章

分割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 标签中添加

<?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说拜拜了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐