How to specify the JDK version in android studio?

Tags: , , ,

Android Studio is giving me a Gradle build error that looks like this:

Error:(3, 22) compileSdkVersion android-22 requires compiling with JDK 7

Now it gives me these clickable prompts:

Download JDK 7
Select a JDK from the File System
Open build.gradle File

And I have already downloaded and installed JDK 7. The problem is when I go to select it in the “File System” i can only find a directory named 1.6.0 JDK. Furthermore, the installation of JDK 7 skipped the bullet point where I would’ve selected the install directory, so I’m really not sure where it is. My java control panel says I have “Java 7 Update 79” so I’m pretty sure I’m close, I just need to tell android studio where it is. I also ran the java -version command in the terminal and it says my version is “1.7.0_79”.

Any help is appreciated!


You can use cmd + ; for Mac or Ctrl + Alt + Shift + S for Windows/Linux to pull up the Project Structure dialog. In there, you can set the JDK location as well as the Android SDK location.

Project Structure Dialog

To get your JDK location, run /usr/libexec/java_home -v 1.7 in terminal. Send 1.7 for Java 7 or 1.8 for Java 8.

Source: stackoverflow