102

I've installed Android Studio 1.1.0. I haven't done anything yet like start new Android application or import anything. Somehow it is trying to build something and it throws sync error.

Error:Unable to start the daemon process. This problem might be caused by incorrect configuration of the daemon. For example, an unrecognized jvm option is used. Please refer to the user guide chapter on the daemon at http://gradle.org/docs/2.2.1/userguide/gradle_daemon.html

Please read the following process output to find out more:


Error occurred during initialization of VM Could not reserve enough space for object heap Could not create the Java virtual machine.

I've already checked at gradle.org/.../gradle_daemon.html but couldn't find anything that helps me to solve the problem.

It isn't a memory problem because I've 8GB of physical memory and no other program running.

trincot
  • 317,000
  • 35
  • 244
  • 286
GummDev
  • 1,160
  • 2
  • 8
  • 13
  • Check your GRADLE_OPTS environment or your gradle.properties, make sure they have the right configurations as the error is saying. – Al Jacinto May 05 '15 at 12:48
  • It shouldn't be necessary to set up GRADLE_OPTS but, no matter what I looked up for gradle.properties in the entire file system and nothing appear to be present. – GummDev May 05 '15 at 15:57
  • 1
    gradle read not only your project gradle.properties, it also read you ~/.gradle/gradle.properties, did you check that as well? – Al Jacinto May 05 '15 at 17:18
  • I did, and parameters for JVM are the same as the parameters already configurated... -Xmx=768m and so on.. – GummDev May 09 '15 at 19:22
  • I know that this is a late answer, but it's given to help other people who may face this problem. If the Gradle build was done properly in the previous times, try restarting the Android Studio, and restarting the computer then try other options. – Mohsen Kamrani Jan 04 '16 at 15:54
  • # Default value: -Xmx512m -XX:MaxPermSize=1024m # org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 – Lucky Rana Jun 21 '16 at 08:20
  • and after adding above configration , just clean and build your project again. – Lucky Rana Jun 21 '16 at 08:21

8 Answers8

227

For Android Studio 1.3 : (Method 1)

Step 1 : Open gradle.properties file in your Android Studio project.

Step 2 : Add this line at the end of the file

org.gradle.jvmargs=-XX\:MaxHeapSize\=256m -Xmx256m

Above methods seems to work but if in case it won't then do this (Method 2)

Step 1 : Start Android studio and close any open project (File > Close Project).

Step 2 : On Welcome window, Go to Configure > Settings.

Step 3 : Go to Build, Execution, Deployment > Compiler

Step 4 : Change Build process heap size (Mbytes) to 1024 and Additional build process to VM Options to -Xmx512m.

Step 5 : Close or Restart Android Studio.

SOLVED - Andriod Studio 1.3 Gradle Could not reserve enough space for object heap Issue

Faiz Siddiqui
  • 2,623
  • 1
  • 15
  • 15
  • Thanks for the answer ... but I did tried this procedure before and didn't worked either. – GummDev Aug 02 '15 at 23:08
  • 2
    Try method 2, it solved my problem. (Try changing the Max heap size, in case it won't work). – Faiz Siddiqui Aug 03 '15 at 06:54
  • Didn't saw method 2 at the very first time ... it worked !! Thank you very much. – GummDev Aug 04 '15 at 14:46
  • 2
    @AZ_: Can't blame Google. This is not 20th century. Things're going 10 times fast than last century's. No time for ellegant quality. Besides, you use it for free. What can you ask more? Thank god, there's stackoverflow :) – Scott Chu Dec 10 '15 at 13:42
  • Only 1st method works for me. Method 2 produces the same error. – Desik Dec 24 '15 at 00:54
  • 5
    I don't understand, I can't find any file called gradle.properties – Majda Mar 02 '16 at 19:41
  • thxs 1st one work "org.gradle.jvmargs=-XX\:MaxHeapSize\=256m -Xmx256m" – sms247 Mar 24 '16 at 06:32
  • I have the same error. I do that but not solve the problem and I have this error. – H.Ghassami Apr 03 '16 at 10:53
  • @AjayPandya try option 1. – Faiz Siddiqui May 12 '16 at 17:30
  • First method worked, but had to restart Intellij too (2016.1.3). Any idea why did it happened? It worked for some time without any problems. – duo Jun 21 '16 at 10:55
  • 5
    What @Majda said. The project has no such file called `gradle.properties`. There's `build.gradle`, `settings.gradle`, `local.properties`, and `gradle-wrapper.properties`. The whole reason I found this answer is because the build output says to edit the project's `gradle.properties`, and no such file exists in the project! – aroth Jul 29 '16 at 02:08
  • Method 1 solved my problem. My Android studio version is 1.1.0. – Alireza Kazemi Jan 07 '18 at 09:48
  • method 2 not solved problem. i think - i have small memory – Роман Зыков Aug 19 '18 at 09:55
  • As of Android Studio version 3.3.2 the option is `Shared build process VM options:` if you want to configure this for all builds. – iyrin Apr 03 '19 at 05:44
44

in gradle.properties, you can even delete

org.gradle.jvmargs=-Xmx1536m

such lines or comment them out. Let android studio decide for it. When I ran into this same problem, none of above solutions worked for me. Commenting out this line in gradle.properties helped in solving that error.

Kashyap Kotak
  • 1,888
  • 2
  • 19
  • 38
21

Add the following line in MyApplicationDir\gradle.properties

org.gradle.jvmargs=-Xmx1024m
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
kay27
  • 897
  • 7
  • 16
  • 1
    This worked for me on a Windows box. I changed gradle.properties from `org.gradle.jvmargs=-Xmx1536m` to `org.gradle.jvmargs=-Xmx1024m` – EmpathicSage Mar 02 '19 at 03:32
19

I tried several solutions, nothing seemed to work. Setting my system JDK to match Android Studio's solved the problem.

Ensure your system java

java -version

Is the same as Androids

File > Project Structure > JDK Location
user1389749
  • 191
  • 1
  • 3
  • In my case (Android studio 1.1 32 bit) using the older jdk path worked. From 1.7 to 1.6. – Rohit Rokde Jan 25 '16 at 05:59
  • Saved my day!~ Now I understand where the problem comes from. It's because before I had 4gb ram and 32 bit jdk inside AS. Now I have 16gb RAM and 32bit JDK just couldn't start because it must initialize all of my ram before it fires. – LPVOID Aug 19 '18 at 16:25
  • how to "Setting my system JDK to match Android Studio's" ? – Harun Jan 29 '19 at 09:42
14

My fix using Android Studio 3.0.0 on Windows 10 is to remove entirely any jvm args from the gradle.properties file.

I am using the Android gradle wrapper 3.0.1 with gradle version 4.1. No gradlew commands were working, but a warning says that it's trying to ignore any jvm memory args as they were removed in 8 (which I assume is Java 8).

Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135
2

I ran into the same issue, here's my post:

Android Studio - Gradle build failing - Java Heap Space

exec summary: Windows looks for the gradle.properties file here:

C:\Users\.gradle\gradle.properties

So create that file, and add a line like this:

org.gradle.jvmargs=-XX\:MaxHeapSize\=256m -Xmx256m

as per @Faiz Siddiqui post

Community
  • 1
  • 1
Lucky Mike
  • 779
  • 2
  • 6
  • 17
1

Faced this issue on Android studio 4.1, windows 10.

The solution that worked for me:

1 - Go to gradle.properties file which is in the root directory of the project.

2 - Comment this line or similar one (org.gradle.jvmargs=-Xmx1536m) to let android studio decide on the best compatible option.

3 - Now close any open project from File -> close project.

4 - On the Welcome window, Go to Configure > Settings.

5 - Go to Build, Execution, Deployment > Compiler

6 - Change Build process heap size (Mbytes) to 1024 and VM Options to -Xmx512m.

Now close the android studio and restart it. The issue will be gone.

Ali Nawaz
  • 2,016
  • 20
  • 30
0

Solution for Android Studio 2.3.3 on MacOS 10.12.6

Start Android Studios with more heap memory:

export JAVA_OPTS="-Xms6144m -Xmx6144m -XX:NewSize=256m -XX:MaxNewSize=356m -XX:PermSize=256m -XX:MaxPermSize=356m"
open -a /Applications/Android\ Studio.app
arm
  • 605
  • 1
  • 7
  • 16