[英]how to use android-support-multidex.jar for phone prior to Android 5.0 in android studio?
I want to build my app with more classes.dex file in one apk. 我想在一个APK中使用更多classes.dex文件构建我的应用。 So I follow instruction of google help page.
因此,我遵循Google帮助页面的说明。 It is ok for android 5.0, But i cannot build for phone prior to Android 5.0.
对于Android 5.0来说还可以,但是我无法在Android 5.0之前为手机构建。 it always report:com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded.
它总是报告:com.android.dex.DexException:--main-dex-list中的类太多,超出了main dex的容量。 I don't know hot to build.
我不知道要建什么。 My build gradle:
我的构建gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
//buildToolsVersion "20"
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.android.ccbtest.first"
minSdkVersion 21
targetSdkVersion 21
multiDexEnabled true
}
dexOptions {
preDexLibraries = false
}
afterEvaluate {
tasks.matching {
it.name.startsWith('dex')
}.each { dx ->
if (dx.additionalParameters == null) {
dx.additionalParameters = []
}
dx.additionalParameters += '--multi-dex' // enable multidex
// optional
// dx.additionalParameters += "--main-dex list=$projectDir/<filename>".toString() // enable the main-dex-list
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile files('libs/ccbtest.jar')
compile files('libs/ccbtest1.jar')
compile files('libs/ccbtest2.jar')
compile files('libs/ccbtest3.jar')
compile files('libs/ccbtest4.jar')
compile files('libs/ccbtest5.jar')
compile files('libs/ccbtest6.jar')
// Multi-dex Lib
compile 'com.android.support:multidex:1.0.0'
}
if i modify minSdkVersion 21 from 21 to 20. It will fail. 如果我将minSdkVersion 21从21修改为20。它将失败。
I want to in phone prior to android 5.0. 我想在Android 5.0之前的手机中使用。 Please help me about this.
请帮助我。
thanks. 谢谢。
br br
mwt 毛重
. 。
First of all, as oberflansch commented , remove the closure that you're passing to afterEvaluate
. 首先,正如oberflansch 所说 ,请删除要传递给
afterEvaluate
的闭包。 The Android gradle plugin will handle all the dx configuration automatically once you've specified multiDexEnabled = true
. 一旦指定
multiDexEnabled = true
,Android gradle插件将自动处理所有dx配置。
The Too many classes in --main-dex-list, main dex capacity exceeded
error most probably says that your main dex file exceeded the 65536 methods limit. Too many classes in --main-dex-list, main dex capacity exceeded
错误,很可能表示您的main dex文件超出了65536个方法的限制。
I have encountered the same issue in the past, and eventually had to patch the Android gradle plugin to not include Activity classes in main dex. 我过去曾遇到过相同的问题,最终不得不修补Android gradle插件,使其在主dex中不包括Activity类。 It's a bit hacky, but works well.
这有点hacky,但是效果很好。 See my blogpost for further explanation.
看到我的博客文章进一步的解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.