如何在实验性Gradle插件中使用dexOption?

时间:2016-04-28 10:53:34

标签: android gradle android-gradle

构建代码时出现 OutOfMemory 错误。我尝试在我的实验性 build.gradle 文件中添加dexOption,如下所示:

model {

    def signConf = new String()

    android {
        compileSdkVersion = COMPILE_SDK_VERSION as int
        buildToolsVersion = BUILD_TOOLS_VERSION

        defaultConfig.with {
            applicationId = "x.y.z.k"
            minSdkVersion.apiLevel = MIN_SDK_VERSION as int
            targetSdkVersion.apiLevel = TARGET_SDK_VERSION as int
            versionCode = VERSION_CODE as int
            versionName = VERSION_NAME
            multiDexEnabled = true
            testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"


        }

        dexOptions {
            javaMaxHeapSize "2048M"

        }
    }
}

使用dexOption我收到以下错误:

Error:Cause:com.android.build.gradle.managed.AndroidConfig_Impl

如何在使用实验性Gradle插件进行编译时添加dexOption

1 个答案:

答案 0 :(得分:2)

对我有用的是将dexOptions放在android {}块之外并将其命名为android.dexOption。

例如。

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.3"

        defaultConfig {
          ...
        }

        ndk {
           ...
        }

        buildTypes {
           ...
        }

        productFlavors {
            ...
        }
    }
    android.dexOptions {
        javaMaxHeapSize = "2g"
    }
}

dependencies {
...
}
相关问题