为了在进程中运行 dex,Gradle 守护进程需要更大的堆.它目前有大约 910 MB [英] To run dex in process, the Gradle daemon needs a larger heap. It currently has approximately 910 MB

查看:20
本文介绍了为了在进程中运行 dex,Gradle 守护进程需要更大的堆.它目前有大约 910 MB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次运行我的应用程序时,我都会收到此 Gradle 错误.错误是:

I am getting this Gradle error every time I run my app. The error is:

要在进程中运行 dex,Gradle 守护进程需要更大的堆.它目前大约有 910 MB.

To run dex in process, the Gradle daemon needs a larger heap. It currently has approximately 910 MB.

要加快构建速度,请将 Gradle 守护程序的最大堆大小增加到 2048 MB 以上.

For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.

要做到这一点,在项目 gradle.properties 中设置 org.gradle.jvmargs=-Xmx2048M.如需更多信息,请参阅https://docs.gradle.org/current/userguide/build_environment.html

To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties. For more information see https://docs.gradle.org/current/userguide/build_environment.html

这是我的 build.gradle (Module:app) 文件:

Here is my build.gradle (Module:app) file:

apply plugin: 'com.android.application'

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.3"

        defaultConfig {
            applicationId "mobileapp.tech2dsk"
            minSdkVersion 15
            targetSdkVersion 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:23.3.0'
        compile 'com.android.support:design:23.3.0'
    }

这是我的 build.gradle(Project) 文件:

And here is my build.gradle(Project) file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是我的 gradle.properties 文件:

and here is my gradle.properties file :

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

推荐答案

2017 年 6 月 25 日更新

在 2017 年 Google IO 上有一些关于这个主题的更新.不再推荐在dexOptions上设置标志,所以如果你有类似下一个的东西,你可以删除它.

At Google IO 2017 there was some updates about this topic. It's not recommended anymore to set the flag on the dexOptions, so if you have something like the next, you can delete it.

dexOptions {
   javaMaxHeapSize "2g"
}

  • 来源:加快您的 Android Gradle 构建
  • 原答案:

    Android Studio 2.1 启用 Dex In Process,它与 Gradle 共享虚拟机以缩短构建时间.因此,有必要增加 Gradle 守护进程的大小以合并这些 Dex 进程.

    Android Studio 2.1 enables Dex In Process which shares the VM with Gradle to improve build times. Due to this, it's necessary to increase the size of the Gradle daemon to incorporate those Dex processes.

    至少需要 2 gig 的内存,但如果您负担得起,您可以尝试使用 3 g.

    At least it's necessary 2 gigs of memory, but you can try with three if you can afford it.

    gradle.properties.

    gradle.properties.

    org.gradle.jvmargs=-Xmx3072m
    

    默认情况下,Java 最大堆大小为 1 gig,但如果您在 build.gradle 文件中修改了它...

    By default the Java max heap size is one gig, but in case you have modified it on the build.gradle file...

    build.gradle(应用)

    build.gradle (App)

    dexOptions {
       javaMaxHeapSize "2g"
    }
    

    ...你必须相应地调整 Gradle 守护进程的大小(必须更大以适应堆).

    ...you have to resize the Gradle daemon size accordingly (has to be bigger to fit the heap).

    • 资源

    1. 官方博文作者:Reto Meier
    2. Android 官方视频开发人员
    3. DexOptions 文档.

    注意事项:

    • 请注意上述数字因机器而异.

    这篇关于为了在进程中运行 dex,Gradle 守护进程需要更大的堆.它目前有大约 910 MB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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