To run dex in process, the Gradle daemon needs a l

2019-01-10 18:07发布

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

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

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

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

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'
    }

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
}

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

13条回答
可以哭但决不认输i
2楼-- · 2019-01-10 18:50

You can go ahead and change build.gradle like that (like Veeresh Charantimath suggested):

android {
 dexOptions {
    javaMaxHeapSize "2g"
 }
}

And then you might have to mess around with MultiDex stuff (you will need it for big android projects). But your problem may be simpler. There is some chance that you compile and include in your project some not needed libraries. I faced this issue on my tiny project. Here is what I did to fix it:

I removed this from build.gradle:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

And I manually removed my build folder from application root. Problem solved.

查看更多
三岁会撩人
3楼-- · 2019-01-10 18:51

Add in your Build.gradle

android {
 dexOptions {
    javaMaxHeapSize "4g"
  }
}

More info - Android Gradle: What is javaMaxHeapSize "4g"?

查看更多
不美不萌又怎样
4楼-- · 2019-01-10 18:52

Simply leave that on your gradle.properties:

org.gradle.jvmargs=-Xmx2048m 

You can look at that article as reference.

查看更多
戒情不戒烟
5楼-- · 2019-01-10 18:53
  • Please check at first gradle.propertises at your project root directory.

If it is absence, please create a file as like this , then add org.gradle.jvmargs=-Xmx1536m

otherwise if already there , please increase the size.

I have faced same problem , where i have solved by this way.

查看更多
beautiful°
6楼-- · 2019-01-10 18:53

Is it an error or a warning?

Sometimes this is only a warning and I can manage to build it successfully:

:transformClassesWithDexForDebug
To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
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
:mergeDebugJniLibFolders UP-TO-DATE
:transformNative_libsWithMergeJniLibsForDebug
:processDebugJavaRes UP-TO-DATE
:transformResourcesWithMergeJavaResForDebug
:validateDebugSigning
:packageDebug
:zipalignDebug
:assembleDebug
:cdvBuildDebug

BUILD SUCCESSFUL

Total time: 3 mins 44.991 secs
Built the following apk(s):
(...)

So the problem that may prevent a successful build may be another one...

查看更多
Summer. ? 凉城
7楼-- · 2019-01-10 18:56

Try this

defaultConfig {
    ...

    // Enabling multidex support.
    multiDexEnabled true
}
查看更多
登录 后发表回答