How to specify the JDK version in Android Studio?

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 would be appreciated!

243583 次浏览

你可以在 Mac 中使用 cmd + ;,在 Windows/Linux 中使用 Ctrl + Alt + Shift + S来打开项目结构对话框。在这里,您可以设置 JDK 位置以及 Android SDK 位置。

Project Structure Dialog

要获取 JDK 位置,请在终端中运行 /usr/libexec/java_home -v 11。Java 7发送1.7,Java 8发送1.8,Java 11发送11。

对于新的 Android Studio 版本,转到 C: Program Files Android Studio jre bin (或 Android Studio 安装文件的位置) ,在这个位置打开命令窗口,在命令提示符中输入以下命令:-

java -version

在 Mac 上,你可以使用终端进入 /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home(或者你的 Android SDK 安装在任何地方) ,然后在命令提示符中输入以下内容:

./java -version

这是个老问题了,但我的回答仍然可以帮助某人

为了在 android 工作室版本中检查 Java 版本, 只需打开 Android Studio 的终端并键入

java -version

这将显示安装在 android 工作室中的 Java 版本

在 Android Studio 4.0.1中,Help-> About 显示了工作室使用的 Java 版本的详细信息,在我的例子中:

Android Studio 4.0.1
Build #AI-193.6911.18.40.6626763, built on June 25, 2020
Runtime version: 1.8.0_242-release-1644-b01 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1237M
Cores: 8
Registry: ide.new.welcome.screen.force=true
Non-Bundled Plugins: com.google.services.firebase

安卓北极狐工作室(2020.3.1)

在 Android Studio Arctic Fox (2020.3.1补丁4)中,JDK Location 设置被移动到:

File > Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK

直到 Android Studio 4.2

您可以按照 Ben Kane 给出的答案,JDK Location 设置位于:

File > Project Structure > SDK Location

Check the JDK you use in Android Studio

gradle sync使用以下 JDK 位置:

In Android Studio, File -> Project Structure

导航到 SDK Location

Android Studio 4.1.0 JDK Location

cd /Applications/Android\ Studio\ 4.1.0.app/Contents/jre/jdk/Contents/Home


➜  Home ./bin/java --version
openjdk 11.0.8 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
OpenJDK 64-Bit Server VM (build 11.0.8+10-b944.6916264, mixed mode)
  1. gradle.properties:org.gradle.java.home=/Applications/Android\ Studio.app/Contents/jre/Contents/Home
  2. ./gradlew 集成 Debug-Dorg.gradle.java.Home =/Applications/Android Studio.app/content/jre/content/Home