如何使用Android系统的支持,multidex.jar事先电话为Android 5.0在Android Studio中? [英] how to use android-support-multidex.jar for phone prior to Android 5.0 in android studio?

查看:179
本文介绍了如何使用Android系统的支持,multidex.jar事先电话为Android 5.0在Android Studio中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有更多classes.dex文件构建我的应用程序在一个APK。所以我效仿谷歌帮助页面的指令。这是确定的是Android 5.0,但我不能前的是Android 5.0打造的手机。它总是报告:com.android.dex.DexException:太多类 - 主-DEX-名单,主要DEX能力突破。我不知道热建。我的gradle构建:

I want to build my app with more classes.dex file in one apk. So I follow instruction of google help page. It is ok for android 5.0, But i cannot build for phone prior to Android 5.0. it always report:com.android.dex.DexException: Too many classes in --main-dex-list, main dex capacity exceeded. I don't know hot to build. My build 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'
}

如果我从21修改的minSdkVersion 21至20它将失败。

if i modify minSdkVersion 21 from 21 to 20. It will fail.

我要在手机之前的是Android 5.0。请帮我这个问题。

I want to in phone prior to android 5.0. Please help me about this.

感谢。

BR

MWT

推荐答案

首先,作为oberflansch <一个href=\"http://stackoverflow.com/questions/32753991/how-to-use-android-support-multidex-jar-for-phone-prior-to-android-5-0-in-androi#comment53355615_32754596\">commented,删除你传递给 afterEvaluate 关闭。一旦你指定的gradle的Andr​​oid插件会自动处理所有的DX配置 multiDexEnabled = TRUE

First of all, as oberflansch commented, remove the closure that you're passing to afterEvaluate. The Android gradle plugin will handle all the dx configuration automatically once you've specified multiDexEnabled = true.

有太多的类 - 主-DEX-名单,主要DEX能突破错误最有可能说,您的主要DEX文件 超过65536的方法限制。

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.

我也遇到同样的问题,在过去,并最终不得不修补了Android gradle这个插件,不包括主要DEX活动课。这是一个有点哈克,但效果很好。请参见我的博文作进一步的解释。

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. It's a bit hacky, but works well. See my blogpost for further explanation.

这篇关于如何使用Android系统的支持,multidex.jar事先电话为Android 5.0在Android Studio中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆