引用第三方库的jar文件,都有可能会触发这个错误。解决方案如下:

参考《[Android]Cannot fit requested classes in a single dex file. Try supplying a main-dex list.

一、在app的build.gradle中添加依赖,在defaultConfig中添加以下代码【注意:必须是app这个module,不能是其他的module】

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.why.project.poidemo"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" //
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
} //poi
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
} dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation 'com.android.support:multidex:1.0.3'
}

二、如果你自定义了Application子类,需要在这个子类中重写一个方法

@Override
public void onCreate() {
super.onCreate();
// 主要是添加下面这句代码
MultiDex.install(this);
}

Error: Cannot fit requested classes in a single dex file (# methods: 149346 > 65536)的更多相关文章

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

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

  2. CentOS编译安装Apache 2.4.x时报错:configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

    先前按照这篇文章“CentOS6.x编译安装LAMP(2):编译安装 Apache2.2.22”去编译安装Apache2.2.x版本时,安装得挺顺利,今天换成Apache2.4.x版本,安装方法一样, ...

  3. PYCURL ERROR 22 - "The requested URL returned error: 403 Forbidden"

    RHEL6.5创建本地Yum源后,发现不可用,报错如下: [root@namenode1 html]# yum install gcc Loaded plugins: product-id, refr ...

  4. configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

    Apache在2.4版本以后,编译时: # ./configure \ --prefix=/usr/local/apache2 \ --with-included-apr \ --enable-so ...

  5. Error: MDM failed command. Status: Only a single SDC may be mapped to this volume at a time

    映射一个volume到多个SDC的时候报错如下: Error: MDM failed command.  Status: Only a single SDC may be mapped to this ...

  6. 002——keil-Error: L6915E: Library reports error: __use_no_semihosting was requested解决

    ..\OBJ\KEY.axf: Error: L6915E: Library reports error: __use_no_semihosting was requested, but _ttywr ...

  7. 安装docker报错:https://download.docker.com/linux/centos/7/i386/stable/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"

    如题,执行docker安装命令报错: [root@centos ~]# yum install docker-ce Loaded plugins: fastestmirror, security Se ...

  8. yum异常: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"

    http://people.centos.org/hughesjr/chromium/6/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 ...

  9. Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.

    启动tomcat, 出现, ( 之前都是好好的... ) [lk ] ERROR [08-12 15:10:02] [main] org.springframework.web.context.Con ...

随机推荐

  1. Linux学习之文件系统权限及表示

    三类人 用户主(user:u):文件的所有者 同组人(group:g):与文件主同组的用户 其他人(other:o):除用户主和同组人外的其他所有人 三种权限 读权限(r):指用户对文件或目录的读许可 ...

  2. Python数据分析实战

    Python数据分析实战(高清版)PDF 百度网盘 链接:https://pan.baidu.com/s/1nlHM1IW8MYg3z79TUwIsWg 提取码:ux8t 复制这段内容后打开百度网盘手 ...

  3. dubbo+zookeeper报错:com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method

    com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method可能的错误原因有三个前两个是从网上摘得, 第三个是自己解决的 1.需要进行 ...

  4. TypeScript-封装

    class People { private _name: string; age: number; print() { return this._name + ":" + thi ...

  5. 初始化git库并配置自动部署

    1.初始化库 git init --bare wap.git 2.配置wap.git/config文件 [core] repositoryformatversion = 0 filemode = tr ...

  6. [LeetCode] Image Overlap 图像重叠

    Two images A and B are given, represented as binary, square matrices of the same size.  (A binary ma ...

  7. 关于height、offsetheight、clientheight、scrollheight、innerheight、outerheight的区别

    二.也是平时经常用到的offsetheight 它返回的高度是内容高+padding+边框,但是注意哦,木有加margin哦,当然一般也木有啥需要把margin加进去的,以上代码为例,结果显示上图h2 ...

  8. Windows系统MySQL安装配置

    MySQL是一个开放源代码的数据库管理系统,是由MySQL AB公司开发.发布并支持的,现在属于Oracle旗下产品. 与其他大型数据库管理系统如Oracle.DB2.SQL Server等相比,虽然 ...

  9. AWS MVC 详解

    由于新工作是在AWS PaaS平台上进行开发,为不耽误工作,先整理一下AWS MVS的使用规范,快速上手.对AWS PaaS平台的相关介绍留到以后再来补充.本文几乎是对官方学习文档的整理,有遗漏的后补 ...

  10. 错误:Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file

    Java HotSpot(TM) 64-Bit Server VM warning: Insufficient space for shared memory file: /tmp/hsperfdat ...