问题
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!
回答1:
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.

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.
回答2:
For new Android Studio versions, go to C:\Program Files\Android\Android Studio\jre\bin(or to location of Android Studio installed files) and open command window at this location and type in following command in command prompt:-
java -version
回答3:
On a Mac, you can use terminal to go to /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
(or wherever your Android SDK is installed) and enter the following in the command prompt:
./java -version
来源:https://stackoverflow.com/questions/30631286/how-to-specify-the-jdk-version-in-android-studio