本文介绍了即使设置了Min SDK 21,也会出现MultiDex错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事的项目有180k个方法.我已经读过博客和文章,文章中写道,如果将Min SDK设置为21,则不需要MultiDex.但是,如果我从此处删除MultiDex,则会显示65k MultiDex错误消息.以下是我的gradle文件.我不知道我是否不了解这个概念或其他东西.请引导我.

The project i am working on has around 180k Methods. I have read blogs, and articles where its written that if you set your Min SDK to 21, then you don't need MultiDex. But if i remove MultiDex from here it gives me the 65k MultiDex error message. Following is my gradle file. I don't know whether i failed to understand the concept or something else. Kindly guide me.

compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {

    applicationId 'com.myapp.app'
    minSdkVersion 21
    targetSdkVersion 23
    versionCode 59
    versionName "1.0.1"
    multiDexEnabled true
    ndk {
        abiFilters "armeabi", "armeabi-v7a", "x86"
    }
}
dexOptions {
    javaMaxHeapSize "4g" //specify the heap size for the dex process
}
lintOptions {
    abortOnError false
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

productFlavors {
}

推荐答案

按照 MultiDex指南中的对Android 5.0和更高版本的Multidex支持"说明进行操作,即使您使用minSdk 21,您仍然需要使用multiDexEnabled true进行编译.您不需要做的是通过以下方式包含MultiDex支持库:

As per the "Multidex support for Android 5.0 and higher" instructions in the MultiDex guide, even if you minSdk 21 then you still need compile with multiDexEnabled true. What you don't need to do is include the MultiDex support library via:

compile 'com.android.support:multidex:1.0.0'

或在Application类中调用MultiDex.install(Context).

64K方法问题是DEX文件格式的限制,而不是Android平台本身的限制.这两个版本之间的区别在于,Android 5.0+知道如何自动将多个DEX文件加载到单个OAT文件中并从中加载类,而5.0之前的Android版本需要支持库才能从辅助DEX文件中加载类(例如classes2.dex,classes3.dex等).

The 64K method problem is a limitation of the DEX file format and not of the Android Platform itself. The difference between the two versions is that Android 5.0+ knows how to automatically load multiple DEX files into a single OAT file and load classes from it while Android versions prior to 5.0 require the support library in order to load classes from secondary DEX files (e.g. classes2.dex, classes3.dex, etc).

这篇关于即使设置了Min SDK 21,也会出现MultiDex错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 04:48