Gradle sync failed Invalid Project Jdk

unitedartinc picture unitedartinc · Dec 4, 2015 · Viewed 9.6k times · Source

Getting fed up with this problem, heard android studio is better than eclipse in many ways, but I cant even start a single project with it because of this error, tried many solutions still its showing same thing, First i thought it was only when importing old eclipse project, but its not.

1) I tried uninstalling every jdk and jre and installed latest JDK 1.8.0_65 and set all paths and JAVA_HOME

C:\Users\username>java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

C:\Users\username>javac -version
javac 1.8.0_65

C:\Users\username>set JAVA_HOME
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_65

2) Reinstalled android studio

3) Updated all sdk using sdk manager

still if i try to start a new project, i am getting the error

8:10:45 PM Invalid Project JDK
           Please choose a valid JDK directory
           Open JDK Settings
8:10:45 PM Gradle sync started
8:10:45 PM Gradle sync failed: Invalid Project Jdk

JDK Location by default it is showing C:\Program Files\Java\jdk1.7.0_10, And i am changing it to C:\Program Files\Java\jdk1.8.0_65, But seems like its not getting applied. By the way, I am using 64 bit windows 7 and installed 64 bit java.Hope someone can guide me from this mess, its been few night am wasting time on this.

Adding screenshot of my JAVA_HOME enter image description here

Below is the screenshot of JDK location that is showing inside android studio

enter image description here

Answer

George Pantazes picture George Pantazes · Feb 9, 2016

In Android Studio 1.5.1, this error was shown in red: "Android SDK location should not contain whitespace, as this can cause problems with the NDK tools." The problem was never with the JDK location. It was with the SDK Location.

I moved the SDK folder out of Program Files because of the whitespace, changed D:\Program Files\Android\sdk to D:\Android\sdk, and the JDK location then stayed. Android Studio does not seem to like saving the JDK location value if there is an error with the SDK location.