How to specify the JDK version in Android Studio?
JavaAndroidGradleDirectory StructureJava Problem Overview
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!
Java Solutions
Solution 1 - Java
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.
Solution 2 - Java
Android Studio Arctic Fox (2020.3.1)
In Android Studio Arctic Fox (2020.3.1 Patch 4), the JDK Location setting is moved to:
File > 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
Solution 3 - Java
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
Solution 4 - Java
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
Solution 5 - Java
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
Solution 6 - Java
The gradle sync
uses the following JDK location:
In Android Studio, File
-> Project Structure
Navigate to the SDK 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)
Solution 7 - Java
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
Solution 8 - Java
- gradle.properties:org.gradle.java.home=/Applications/Android\ Studio.app/Contents/jre/Contents/Home
- ./gradlew assembleDebug -Dorg.gradle.java.home=/Applications/Android\ Studio.app/Contents/jre/Contents/Home