11

I tried to use Android Studio 0.1 to build a small project for practice, but when I make my module, Android Studio says:

Android Dex: [(Module Name)] Error occurred during initialization of VM
Android Dex: [(Module Name)] Could not reserve enough space for object heap

I'm using Windows 7 64-bit, JDK 1.7, with 8GB RAM. I'm not familiar with gradle and don't have an idea how to workaround it. My another almost same PC does not have this problem.

I have tried to modify studio.exe.vmoptions in bin folder, and can see the right-down corner change to 742M when I set -Xmx768M. But the error still occurs. Also, if I want to set a larger value like -Xmx2G, the studio.bat shows:

Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Then the Android Studio just does not start up.

Is there a way to make my Android Studio usable? Thank you very much.

Romulus Urakagi Ts'ai
  • 3,699
  • 10
  • 42
  • 68

4 Answers4

12

For 64 bit users.

  1. Click Start.
  2. type Environment.
  3. Click Edit System Environment Variables.
  4. A dialog will pop up, click the button labeled Environment Variables.
  5. Locate JAVA_HOME set it to C:\Program Files\Java\$YOUR_JAVA_VER where $YOUR_JAVA_VER = jdk1.7.0_21. (You can check your Java version by actually navigating to C:\Program Files\Java\ and looking for your JDK.)

If there is no JAVA_HOME you may need to create it.

Victorio Berra
  • 2,760
  • 2
  • 28
  • 53
6

setting gradle options lower than default made it work for me. it depends on the hardware resources that you have access to.

go to
.settings .Compiler (Gradle-based Android Projects) .in VM Options field set -Xmx128m -Xms128m

demian
  • 632
  • 7
  • 14
  • 2
    Just in case anyone else is seeing this outside Android Studio, this can be set by creating a environment variable _JAVA_OPTIONS with value -Xmx512M. http://www.tomsguide.com/faq/id-1761312/fix-create-java-virtual-machine-issue.html – Chris Rae Jun 15 '15 at 14:48
  • @ChrisRae Thanks Chris. I guess your comment should be posted as an answer. – Gandhi Dec 15 '16 at 07:12
6

For Android studio - Solution here.

Community
  • 1
  • 1
Faiz Siddiqui
  • 2,623
  • 1
  • 15
  • 15
3

Go to File -> Settings.

In the search bar type heap.

You'll see highlighted in Compiler section Compiler process heap size.

There's a couple of other options for heap.

Generally speaking, the search function in the settings of Intellij is rather good.

Thibault D.
  • 10,041
  • 3
  • 25
  • 56
  • @PseudoNinja In my case I had to lower the `Android DX Compiler` heap memory. By default it was 1024MB and lowering it to 768MB works fine. – telkins Jul 26 '13 at 17:40