Gradle in Android Studio giving error Project sync failed
Asked Answered
J

10

9

I am new to Android Studio.I installed Android Studio-1.2.1.1 and i have jdk1.7.0_40 installed.I am facing problem with gradle build. For reference you can check gradle issue

I am getting following error in messages

Error:The newly created daemon process has a different context than expected.
Java home is different.
Expecting: 'C:\Program Files\Java\jdk1.7.0_40' but was: 'C:\Program Files\Java\jdk1.7.0_40\jre'.
Please configure the JDK to match the expected one.
<a href="open.project.structure">Open JDK Settings</a>

All i understood is gradle is using JRE and Android Studio is using JDK and due to that two JAVA_HOME's are different and giving errors.

I tried downloading gradle 2.3 and changed gradle path in android studio to this file,still same problem.

Judon answered 4/6, 2015 at 11:43 Comment(0)
S
1

EDIT: I fixed this issue by uninstalling all the jdk installation & updates then reinstall only one jdk and assure its env. variables


I do not have a solution but I have the same problem it happens as the android studio opens from java_home/jre thence all JVMs that will fork next will come from this path, while your system varible tells Gradle to get his java.exe from JAVA_HOME

I tried to make gradle read from jre but it falied also i tried to make android studio open from java_home/bin but it falid also

Stratus answered 5/9, 2015 at 21:9 Comment(0)
E
14

This is a very late answer but I see that a common suggestion is to remove all other jdk's and this is not always the best idea. You might need older jdk's for different projects. You can go into the gradle.properties file for the project and enter the following line (varied based on your version):

org.gradle.java.home=C:/Java/jdk1.8.0_111

If you are using a different jdk just point to a different directory.

Eliaseliason answered 18/12, 2016 at 20:54 Comment(0)
H
1

Replace this

C:\Program Files\Java\jdk1.7.0_40\jre

with

C:\Program Files\Java\jdk1.7.0_40

inside your JAVA_HOME variable

Hereford answered 4/6, 2015 at 11:48 Comment(10)
thanks for reply,but my JAVA_HOME is set to C:\Program Files\Java\jdk1.7.0_40 only ,and with this setting it is giving that errorJudon
Click on the URL 'Open JDK Settings' inside message windowHereford
It is pointing to same location C:\Program Files\Java\jdk1.7.0_40Judon
Have you rebuild the project?Hereford
Have you define JAVA_HOME inside user variable and System both?Hereford
and set Path inside system variable to C:\Program Files\Java\jdk1.7.0_40\bin folderHereford
thanks for reply,JAVA_HOME is defined only as System variable and path variable also pointing to C:\Program Files\Java\jdk1.7.0_40\bin folderJudon
No,I think problem is with some JAVA_HOME pointing by Studio and gradleJudon
Try to Create new Project and then runs. Sometime gradle not changes(Syncs).Hereford
Tried creating new project ,same problemJudon
S
1

EDIT: I fixed this issue by uninstalling all the jdk installation & updates then reinstall only one jdk and assure its env. variables


I do not have a solution but I have the same problem it happens as the android studio opens from java_home/jre thence all JVMs that will fork next will come from this path, while your system varible tells Gradle to get his java.exe from JAVA_HOME

I tried to make gradle read from jre but it falied also i tried to make android studio open from java_home/bin but it falid also

Stratus answered 5/9, 2015 at 21:9 Comment(0)
P
1

For those who are on OS X El Capitan (v10.10) and end up with the above error message.

In my case there was nothing wrong with Gradle, simply my Java 1.8 was "too new" for Android Studio 1.5 so I had to install older 1.7.

I downloaded it from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html (jdk-7u79-macosx-x64.dmg)

After all I had to just update JDK location in the project structure enter image description here

Pod answered 12/12, 2015 at 12:17 Comment(0)
M
0

I already had java jdk 7u17 and I also had got same error as FaizAli.

I try to search and done a lot of changes but not success!

Then, I downloaded jdk 7u80 at this link and installed this jdk. After that those error gone.

Memoirs answered 15/7, 2015 at 2:44 Comment(0)
P
0

What I found out in my case is that the SDK my project pointed to "broke" and I had to fix its "JDK home path":

enter image description here

Peachey answered 18/4, 2019 at 9:57 Comment(0)
J
0

This is 2019. For anyone experiencing this issue... The first thing is to make sure that you correctly set your environment variables as per this instruction: https://www.mkyong.com/java/how-to-set-java_home-on-windows-10/

Which means you should be able to type javac -version and java -version and get the version number inside your Home directory.

Once you can confirm this, then go to the Project Structure inside, the SDK Location > JDK Location select Use JAVA_HOME environment variable.

This was what I did and it worked.

Jus answered 12/5, 2019 at 22:56 Comment(0)
B
-1

I solved it by going to Project Structure then unchecking use embedded JDK and then setting the path to C:\Program Files\Java\jdk1.8.0_121

Burk answered 28/11, 2018 at 9:12 Comment(0)
M
-1

Solved this by going to File -> Project Structure -> SDK Location

and under JDK Location, update with Gradle SDK location.

Micronesian answered 15/7, 2020 at 20:9 Comment(0)
V
-2

This happens because Android is using embedded ( JRE ) which is selected as recommended and at same time Android Studio detects JDK Home_Path (Environmental Variable ) and due to that two JAVA Path are different there is the conflict so it give you Error :

If You remove java_home path or Environmental variable you will get this error:

CreateProcess error=2, The system cannot find the file specified [Android studio

For Android Studio, the solution is to go to File> Other Setting > Default Project Structure> Uncheck the checkbox and browse and set JDK path

Violetavioletta answered 14/9, 2017 at 7:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.