Ali
Ali

Reputation: 808

An error when creating new project in android studio

Every time I create new project i get this error:

Failed to import new Gradle project: Could not fetch model of type 'IdeaProject' using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
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/1.6/userguide/gradle_daemon.html
Please read below process output to find out more:
-----------------------
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.


Consult IDE log for more details (Help | Show Log)

Any Idea?

Upvotes: 22

Views: 44977

Answers (12)

pancodemakes
pancodemakes

Reputation: 574

My answer was found with Android Studio 2.2, which released in September of 2016, so the previous answers that are on this post did not work for me. What did work for me, however, is setting Android Studio to use the integrated JDK instead of the JDK 1.8 that I downloaded. Before setting my JDK to the integrated JDK and not the one I downloaded, I got the same errors as detailed in this post.

This can be found in your Default Project Structure settings. enter image description here

Upvotes: 1

Darshan Singh
Darshan Singh

Reputation: 27

Go to Project and find gradle.propeties and then find:- "org.gradle.jnmargs" replace this line with followings org.gradle.jvmargs=-XX:MaxHeapSize\=256m -Xmx256m

Error in stable version of android-studio 2.2

Upvotes: 1

Gladys Sanchez
Gladys Sanchez

Reputation: 41

You can try:

  • Open your Android Studio >> File >> Settings >> Compiler >> Gradle
  • Set VM Options to -Xmx512m and OK.

Upvotes: 0

Rakib Jewel
Rakib Jewel

Reputation: 1

Open Gradle Properties and change the org.gradle.jvmargs=-Xmx1024m.

and then click try again to synchronize Gradle again.

See The Image

Upvotes: 0

A.T.
A.T.

Reputation: 26302

for me it works by setting up environment variable

GRADLE_OPTS=-Xmx512m

Upvotes: 2

Trouverdice
Trouverdice

Reputation: 21

I resolved by go to ANDROID_SDKPATH/sdk/build-tools/VERSION/dx.bat edit with some text editor change set java_exe=

to

set java_exe=%java_home%\bin\java.exe

or use your java.exe path

and comment

if exist    "%~dp0..\tools\lib\find_java.bat" call    "%~dp0..\tools\lib\find_java.bat"
if exist "%~dp0..\..\tools\lib\find_java.bat" call "%~dp0..\..\tools\lib\find_java.bat"

result like this

set java_exe=%java_home%\bin\java.exe
rem if exist    "%~dp0..\tools\lib\find_java.bat" call    "%~dp0..\tools\lib\find_java.bat"
rem if exist "%~dp0..\..\tools\lib\find_java.bat" call "%~dp0..\..\tools\lib\find_java.bat"
if not defined java_exe goto :EOF

and now it can BUILD SUCCESSFUL

Upvotes: 0

Victorio Berra
Victorio Berra

Reputation: 3105

64 bit users!

There is a chance Gradel is looking at a 32 bit JDK install. So we need to change that (worked for me).

Start -> type "Environment" -> click "Edit System Environment Variables" -> a dialog will pop up, click the button labeled "Environment Variables" -> locate JAVA_HOME set it to "C:\Program Files\Java\$YOUR_JAVA_VER" where $YOUR_JAVA_VER = jdk1.7.0_21.

If there is no JAVA_HOME you may need to create it, when I read the install Wiki I was told I needed to install it.

Upvotes: 29

Sambulo Senda
Sambulo Senda

Reputation: 1418

Start Android Studio, close any open project.

On the right side, click on Configure -> Settings.

On the left side, in Compiler->Gradle set VM Options to "-Xmx512m" (without quotes)

Press OK, then create a project. Worked for me.

Upvotes: 75

EsmaeelQash
EsmaeelQash

Reputation: 498

put the option: -Xmx512m in the compiler >> grandle VM options, not in the general compiler VM options, Don't Replace -ea

Upvotes: 0

Dionisios
Dionisios

Reputation: 51

Antivirus block Java and Android studio. Try to close antivirus and check again...

Upvotes: 4

Brian
Brian

Reputation: 1434

If you are using the latest version of Android Studio (0.2.1 as of this answer), you can go to Android Studio Preferences, expand the Compiler options, and attempt to reduce the maximum allowed memory for the Java Compiler, Groovy Compiler, and Android DX Compiler. Keep reducing until you see a change in outcome. Honestly, it sounds like your computer may just be short on available RAM, and Android Studio may be configured by default to take up a relatively large chunk of memory.

Upvotes: 0

bCliks
bCliks

Reputation: 2958

Try to decrease setting for max heap space setting in the file

android-sdk-windows\platform-tools\dx.bat 

to smaller value. change it to 512M instead of 1024M.

set defaultMx=-Xmx512M

Upvotes: 0

Related Questions