简体   繁体   中英

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!

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 11 in terminal. Send 1.7 for Java 7, 1.8 for Java 8, or 11 for Java 11.

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

java -version

Android Studio Arctic Fox (2020.3.1)

In the Canary 14 of Android Studio Arctic Fox (2020.3.1), the JDK Location setting is moved to:

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

Up to Android Studio 4.2

You can follow the answer from Ben Kane, the JDK Location setting is located in:

File > Project Structure > SDK Location

This is old question but still my answer may help someone

For checking Java version in android studio version , simply open Terminal of Android Studio and type

java -version 

This will display java version installed in android studio

In Android Studio 4.0.1, Help -> About shows the details of the Java version used by the studio, in my case:

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

在 Mac 上,您可以使用终端转到/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home (或安装 Android SDK 的任何位置)并在命令提示符中输入以下内容:

./java -version

检查您在 Android Studio 中使用的 JDK

The gradle sync uses the following JDK location:

In Android Studio, File -> Project Structure

Navigate to the SDK Location .

Android Studio 4.1.0 JDK 位置

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 assembleDebug -Dorg.gradle.java.home=/Applications/Android\\ Studio.app/Contents/jre/Contents/Home

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM