107

I'm trying to generate a signed apk but I always get the same error.

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.

I can´t file that file but I tried modify gradle-wrapper.properties but I still get the same error.

This is my gradle-wrapper.properties file

#Thu May 05 20:51:44 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
org.gradle.jvmargs=-Xmx2048m

I have already try too Android Gradle Could not reserve enough space for object heap

Community
  • 1
  • 1
Ricardo
  • 7,921
  • 14
  • 64
  • 111
  • Possible duplicate of [Where to put the gradle.properties file](http://stackoverflow.com/questions/30333837/where-to-put-the-gradle-properties-file) – ericbn Apr 13 '17 at 18:21

7 Answers7

155

Just create a file called gradle.properties in your root project:

root
|--gradle.properties
|--build.gradle
|--settings.gradle
|--app
|----build.gradle

Then add inside the file:

org.gradle.jvmargs=-Xmx2048m
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • 4
    if you have a global gradle.properties, then make sure you do not have an entry in it. – Ray Tayek Sep 27 '16 at 02:48
  • 7
    And by "global gradle.properties", @RayTayek means one in your home directory, like `~/.gradle/gradle.properties`. Look at this answer for how Gradle looks for the properties file: http://stackoverflow.com/a/30333929/293280 – Joshua Pinter Mar 01 '17 at 14:27
  • Question: is it best to keep a `jvmargs` settings in the global gradle properties or in the project's root directory? – Joshua Pinter Mar 01 '17 at 14:29
  • It depends if you want to use the same properties for all projects. – Gabriele Mariotti Mar 01 '17 at 14:30
  • @GabrieleMariotti (Quick response!) I have two settings in my gradle.properties file now, `daemon=true` and `jvmargs=-Xmx4608M`. Is memory size dependent on the project? And is this something that should be checked in source control? – Joshua Pinter Mar 01 '17 at 14:31
  • 2
    It is the memory used by gradle while building the single project. I usually put them in source control. – Gabriele Mariotti Mar 01 '17 at 14:33
  • 1
    @GabrieleMariotti Awesome, that's what I was thinking as well. Will do. – Joshua Pinter Mar 01 '17 at 14:34
22

In the Project window, right click your Project name and choose New > File. The new file name is "gradle.properties". The content is: org.gradle.jvmargs=-Xmx1536M ;(or the number shown in your Gradle Console) in a line like this: ... increase the maximum heap size for the Gradle daemon to more than 2048 MB.

Ary
  • 251
  • 2
  • 4
7

gradle.properties is located in windows

    C:\Users\<%User_Name%>\.gradle\gradle.properties

In android studio

   `Gradle Scripts` >> `gradle.properties (Global Properties)`
Muhammad Azam
  • 535
  • 7
  • 12
  • It must not be added all the time. I am running Android Studio 3.3.1 and there is no C:\Users\<%User_Name%>\.gradle\gradle.properties – Mark Dail Feb 22 '19 at 15:26
  • You may find in android studio method. – Muhammad Azam Feb 24 '19 at 06:45
  • @MarkDail it is good to add whenever you want a global configuration or variable across your project instead of defining them on each project's `gradle.properties` file – Bitwise DEVS Jun 25 '21 at 14:57
2

Just follow the below steps:

1)Go to File
2)Create a New File
3)Name it as gradle.properties
4)Write the content in the file 
For eg:
 org.gradle.jvmargs=-Xmx1536M;(replace it with the numbers in your gradle file)

Hope it helps.

Chinmaay
  • 153
  • 1
  • 2
  • 10
0

This is a problem which used to disturb me so much but later on got a quick solution.

I tried the methods mentioned by my colleague but it never worked for me.

Incase the problem persists, use this two ways.

Note Changing the gradle heap size may not assist you so much but you can try this two ways to evade this type of error 'Gradle daemon' error.

Close all other application running and restart the android studio. If the error persist, use the second method.

That is close unnecessary processes running on the background by holding down alt+ctrl and then click del button to open the task manager window.

Mostly, browsers tend to run on the background and consume alot of memory that is why you see that Gradle daemon error.

For example, close chrome process which is running on the background and either restart the android studio or rebuild the project

Daniel Nyamasyo
  • 2,152
  • 1
  • 24
  • 23
0

I was also finding for the gradle.properties file to enable/disable AOSP Accelerate Clean Builds with Build Cache as explained in the Android Studio user-guide page.

I found the file here through a simple search find -name 'gradle.properties' inside my AOSP root directory

my_AOSP_root/tools/build/gradle.properties
Yasindu
  • 142
  • 1
  • 10
0

Keep the gradle.properties in the project folder or in the C:\Users\Username.gradle. Please make sure that the name of file is "gradle.properties", not gradle.properties.txt when saving on windiws using notepad.