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

标签 android gradle android-gradle-plugin

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

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

最佳答案

对我有用的是将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 {
...
}

关于android - 如何在实验性Gradle插件中使用dexOption?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36912534/

相关文章:

java - AndroidManifest.xml 文件中的 "allowClearUserData"= "false"

spring - 在spring boot中gradle build(war)时,可以将静态文件放在根目录中吗?

android - 新鲜的 Cordova 建立错误

java - Ant 到 Gradle 转换 : Obfuscation and Jar

android - 程序类型已经存在 : org. hamcrest.CoreMatchers

android - 如何在 Android 模块库中创建 Android 模块库

android - 如何在 Android Studio (ver 2.1.2) 上构建 FFmpeg (ver 3.1.1)

android - 如何在应用程序中添加 GDPR 同意对话框和 GDPR 相关的混淆

android - 如何知道 Intent 是否在android中完成

android - 最新 AOSP 中最新版本的 ADB 是什么?