Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 
like image 234
Rohith Manchikalapati Avatar asked May 07 '16 15:05

Rohith Manchikalapati


People also ask

How much RAM should I allocate to Gradle?

To use this feature, you will need to increase the amount of memory available to the Gradle daemon to at least 2GB (1 GB is the default).

What is Gradle build daemon?

The Daemon is used not only to avoid the cost of starting the JVM for each build but also to cache information about the project structure, files, tasks, and more in memory. This makes the next compilations much faster.

What is org Gradle Jvmargs?

org.gradle.jvmargs - specifies jvmargs used for daemon process. You want to set high enough memory limit to fix dex in Gradle process, so minimum configuration here is -Xmx2g , while 3-4 gigabytes won't hurt either.


1 Answers

Update from June 25, 2017

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" } 
  • Source: Speeding Up Your Android Gradle Builds

Original answer:

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.

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

gradle.properties.

org.gradle.jvmargs=-Xmx3072m 

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

build.gradle (App)

dexOptions {    javaMaxHeapSize "2g" } 

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

Notes:

  • Please realize above numbers varies from machine to machine.
like image 132
Sotti Avatar answered Sep 21 '22 18:09

Sotti