最近将一个老的Eclipse项目转到Android Studio后,用gradle添加了几个依赖,项目可以make,但是一旦run就报错

Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

原因

项目的方法数超过了64k,需要进行分包处理!

Android Studio解决方案:

至于Eclipse的解决方法,似乎需要采用相应插件!

第一步,添加依赖
implementation 'com.android.support:multidex:1.0.1'`
第二步,添加配置,build.gradle(app)
  1. buildTypes
 dexOptions {
preDexLibraries false
}

这里是需要添加到buildTypes中,注意如果app依赖其他的module,那么在相应的moudle(build.gradle)中也需要添加!

2. 在defaultConfig下添加

multiDexEnabled true
第三步,创建MultiDexApplication
  1. 如果你有自定义的Application

    自定义Application 继承 android.support.multidex.MultiDexApplication;,然后重写其attachBaseContext方法
/**
* 方法超过64K,需要采用分包
* fjj 2019-3-27
* @param base
*/
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this); // 初始化
}
  1. 如果你自己的项目没有自定义Application,也不需要自定义时,可直接在AndroidManifest.xmlapplication下指定:
android:name="android.support.multidex.MultiDexApplication;"

最后

此致,敬礼!

Android工程方法数超过64k,The number of method references in a .dex file cannot exceed 64K.的更多相关文章

  1. The number of method references in a .dex file cannot exceed 64K.(转)

    前言 我一直都知道app里面的方法数是有限制的差不多64000,具体的就未曾考证了在遇到这个问题之前,一直以为这个一个多么遥远的距离其实并不是的,稍有不慎这个异常出来了当前并不是你真的有编写了64k的 ...

  2. 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. ...

  3. 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. ...

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

    在Android系统中,一个App的所有代码都在一个Dex文件里面.Dex是一个类似Jar的存储了多有Java编译字节码的归档文件.因为Android系统使用Dalvik虚拟机,所以需要把使用Java ...

  5. 如何处理 android 方法总数超过 65536 . the number of method references in a .dex file exceed 64k

    一:问题描述:     应用中的Dex 文件方法数超过了最大值65536的上限,简单来说,应用爆棚了. 二.解决方案:      方案1:使用插件化框架  比如: https://github.com ...

  6. Android工程方法数超过65535的解决办法

    Error:Execution failed for task ':ttt:transformClassesWithDexForDebug'.com.android.build.api.transfo ...

  7. Android的方法数超过65535问题

    Under the Hood: Dalvik patch for Facebook for Android 先来看一段中文内容 Hack Dalvik VM解决Android 2.3 DEX/Line ...

  8. Android 方法数超过64k、编译OOM、编译过慢解决方案。

    目前将项目中的leancloud的即时通讯改为环信的即时通讯.当引入easeui的时候 出现方法数超过上限的问题. 搜索一下问题,解决方法很简单. 这里简单记录一下,顺序记录一下此解决方案导致的另一个 ...

  9. (转载)Android 方法数超过64k、编译OOM、编译过慢解决方案。

    Android 方法数超过64k.编译OOM.编译过慢解决方案.   目前将项目中的leancloud的即时通讯改为环信的即时通讯.当引入easeui的时候 出现方法数超过上限的问题. 搜索一下问题, ...

随机推荐

  1. 运行TensorFlow报错,“This program requires version 3.6.1 of the Protocol Buffer runtime library, but the installed version is 3.0.0.”

    报错信息: [libprotobuf FATAL google/protobuf/src/google/protobuf/stubs/common.cc:67] This program requir ...

  2. 如何在HHDI中调用Java文件

    创建执行JS语句任务,在脚本中输入相关代码,两种写法: ------------------------写法一 // 直接调用类的路径 var now = com.haohe.utils.DateUt ...

  3. 【八】将日志写入log(glog)

    [任务8]将日志写入log(glog) glog简介 glog是google开源的一个日志系统,相比较log4系列的日志系统,它更加轻巧灵活,而且功能也比较完善 glog配置使用资料 下载glog 命 ...

  4. sqoop import/export使用经验

    一.先创建一个小表(test_01)进行测试(主节点IP:169.254.109.130/oracle服务器IP:169.254.109.100) 1.测试连接oracle; sqoop list-t ...

  5. 嵌入式C语言自我修养 12:有一种宏,叫可变参数宏

    12.1 什么是可变参数宏 在上面的教程中,我们学会了变参函数的定义和使用,基本套路就是使用 va_list.va_start.va_end 等宏,去解析那些可变参数列表我们找到这些参数的存储地址后, ...

  6. 二叉树 ADT接口 遍历算法 常规运算

    BTree.h   (结构定义, 基本操作, 遍历) #define MS 10 typedef struct BTreeNode{ char data; struct BTreeNode * lef ...

  7. Freemarker入门(一)——入门与基本概述

    1.概述 1.文档 完美的中文文档:http://freemarker.foofun.cn/ 2.是什么 FreeMarker是一个用Java语言编写的模板引擎.它基于模板来生成文本输出.Freema ...

  8. 20155222 卢梓杰 myod

    20155222 卢梓杰 myod 复习c文件处理内容 编写myod.c 用myod XXX实现Linux下od -tx -tc XXX的功能 main与其他分开,制作静态库和动态库 编写Makefi ...

  9. 覆盖Django mysql model中save方法时碰到的一个数据库更新延迟问题

    最近有一个需求,通过django的admin后台,可以人工配置5张表的数据,这些数据进行一些业务规则处理后会统一成一份数据缓存在一个cache之中供服务端业务访问,因而任何一张表的数据更新(增.删.改 ...

  10. 【CF613D】Kingdom and its Cities

    [CF613D]Kingdom and its Cities 题面 洛谷 题解 看到关键点当然是建虚树啦. 设\(f[x]\)表示以\(x\)为根的子树的答案,\(g[x]\)表示以\(x\)为根的子 ...