Error: Cannot fit requested classes in a single dex file (# methods: 149346 > 65536)

引用第三方库的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);
}

原文地址:https://www.cnblogs.com/whycxb/p/9792192.html

时间: 2024-11-18 23:48:19

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

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

在Android系统中,一个App的所有代码都在一个Dex文件里面.Dex是一个类似Jar的存储了多有Java编译字节码的归档文件.因为Android系统使用Dalvik虚拟机,所以需要把使用Java Compiler编译之后的class文件转换成Dalvik能够执行的class文件.这里需要强调的是,Dex和Jar一样是一个归档文件,里面仍然是Java代码对应的字节码文件.当Android系统启动一个应用的时候,有一步是对Dex进行优化,这个过程有一个专门的工具来处理,叫DexOpt.DexO

(转)Windows Error 740 – The Requested Operation Requires Elevation

Windows Error 740 – The Requested Operation Requires Elevation What Does Error 740 Mean? If you are experiencing an error 740 message in Windows Vista or Windows 7 when trying to launch an application, it means the software was installed (or has been

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 --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre 出现如下错误: configure: error: Bundled APR requested but not found at ./srcli

Fast, Accurate Detection of 100,000 Object Classes on a Single Machine(转载)

Fast, Accurate Detection of 100,000 Object Classes on a Single Machine 读后记录 这篇文章是CVPR 2013 best paper. 这篇文章的牛,主要体现在一些关键数字上,可以分类100000类别,比base line快了20000倍. 不过,美中不足的是,其单机处理一幅图像的速度,需要20s,而且,100000类mAP为0.16,看上去很美,但是距离实用还有一些距离. 这篇文章的卖点在于速度快,具体就是对于多类检测问题,

An error occurred at line: 1 in the generated java file问题处理

tomcat6启动后,加载jsp页面报错,提示无法将jsp编译为class文件,主要报错信息如下: An error occurred at line: 1 in the generated java file 最后确认该错误原因为:tomcat6不支持jdk1.8版本 修改jdk为1.7,刷新工程,通过!

170318 11:44:26 [ERROR] Can't start server: can't create PID file: No space left on device

数据库挂了.打开远程,进了系统,service mysqld stop 失败.service mysqld start等了好大一会,提示Timeout error occurred trying to start MySQL Daemon 出现Can't start server: can't create PID file: No space left on device这个错误. 提示磁盘空间不足 后用df -h 命令查看 竟然发现磁盘容量全部用完了,于是要查看是谁占用了用命令:find /

android studio创建模拟器报错解决 emulator: ERROR: This AVD's configuration is missing a kernel file!!

android studio创建模拟器报错 emulator: ERROR: This AVD's configuration is missing a kernel file!! 的解决办法 原因有二:1 没有,解决办法通过sdk mangager 下载 2 找不到,解决办法看系统环境变量path(此种情况多数发生在android Studio和EclipseADT同时存在的情况下) 原因是在刚刚安装完毕的androidstudio的sdk目录下没有system-image目录,也许有但没有相

fatal error C1853: 'Debug/***.pch' is not a precompiled header file created with this compiler

出现这个问题,把工程编译选项中的预编译去掉就可以了,操作步骤:首先全部重编译一下工程,如还是不行则试一试将工程设置中C/C++中precompiled   header中选中automatic   use   of   precompiled   headers,并在相应through   header中输入stdafx.h. 另外,rebuild all也是一种方法,或把debug目录下的文件删除,然后重新编译. fatal error C1853: 'Debug/***.pch' is no

报错:An error occurred at line: 22 in the generated java file The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory

org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 22 in the generated java file The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory 加入Myeclipse自带的java EE 6 library即可解决: