56

When signing an apk, I got this message:

To run dex in process, the Gradle daemon needs a larger heap.
It currently has 1024 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to at least 4608 MB (based on the dexOptions.javaMaxHeapSize = 4g).
To do this set org.gradle.jvmargs=-Xmx4608M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html

In my project, I don't have a gradle.properties file, but I have a file called gradle-wrapper.properties.

I opened that file and added the line org.gradle.jvmargs=-Xmx4608M.

After that, I tried to sign the apk again but I'm still getting the message of increasing Gradle heap size.

How to achieve that?

halfer
  • 19,824
  • 17
  • 99
  • 186
NullPointerException
  • 36,107
  • 79
  • 222
  • 382
  • Possible duplicate of [To run dex in process, the Gradle daemon needs a larger heap. It currently has approximately 910 MB](https://stackoverflow.com/questions/37090135/to-run-dex-in-process-the-gradle-daemon-needs-a-larger-heap-it-currently-has-a) – Vidhi Dave Nov 23 '17 at 11:31

6 Answers6

71

If you don't have gradle.properties then go to your project folder you will find gradle files there create a text file and name it as gradle.properties removing .txt and then add the below code to that 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.
org.gradle.jvmargs=-Xmx4096m

# 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

and save it then open your project in Android Studio and click on sync now.

I hope it will resolve your issue, if not please let me know.

Ganesh Satpute
  • 3,664
  • 6
  • 41
  • 78
Pankaj Mundra
  • 1,401
  • 9
  • 25
  • of if you already have `gradle.properties` file in `android` folder add this line `org.gradle.jvmargs=-Xmx4096m` – Amjad Feb 08 '22 at 09:48
31

I know you said your project doesnt have gradle.properties but you could create a global one in C:\Users\user\.gradle and add:

 org.gradle.jvmargs=-Xmx4096M

And remember to run gradle --stop to kill any previous daemons.

LazerBanana
  • 6,865
  • 3
  • 28
  • 47
  • I have tried this to no avail. I even created the command line variable GRADLE_USER_HOME=C:\Users\\.gradle. I also tried putting it in my platform/andorid/gradle.properties but it continues to use 2048MB – Mark A. Rupert Jan 07 '19 at 04:30
12

You can try any one of the following

1) change the gradle.properties file and change the heap size as per your requirement.

If org.gradle.jvmargs=-Xmx2048M is not sufficient then change to 4096 as given

org.gradle.jvmargs=-Xmx4096M enter image description here

2)"Edit Custom VM Options" from the Help menu.

It will open studio.vmoptions / studio64.exe.vmoptions file enter image description here

Change the content to

-Xms128m

-Xmx4096m

-XX:MaxPermSize=1024m

-XX:ReservedCodeCacheSize=200m

-XX:+UseCompressedOops

Save the the file and restart Android Studio.

Nithin
  • 932
  • 7
  • 14
2

Try this link answer

dexOptions 
   {
       javaMaxHeapSize "4g"
   }
....
....
....
ND1010_
  • 3,743
  • 24
  • 41
1

This is Android question, but it pops up for scala out of memory gradle search anyway, so let me try to save some poor souls hours of searching.

Scala forks the JVM by default when compiling, and org.gradle.jvmargs do not apply to it. Instead, you have to pass the args to the Scala plugin in gradle. It depends on your particular setup on where that might be, for me, this works:

tasks.withType(ScalaCompile) {
    configure(scalaCompileOptions.forkOptions) {
        jvmArgs = ['-Xss4m', '-Xmx2048m']
    }
}

If your build is comprised of multiple subprojects, put this inside the subprojects { } block inside the main build.gradle.

Tassadar
  • 1,861
  • 1
  • 15
  • 12
-2

Add following code to your build.gradle file.

 android {
     dexOptions {
     incremental true       
     javaMaxHeapSize "4g"
      }
    }

Reference : Source

Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
Samir Bhatt
  • 3,041
  • 2
  • 25
  • 39