ThePartyTurtle
ThePartyTurtle

Reputation: 2596

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!

Upvotes: 166

Views: 370328

Answers (10)

Ben Kane
Ben Kane

Reputation: 10030

You can use cmd + , for Mac or Ctrl + Alt + S for Windows/Linux to pull up the Settings dialog. Then, go to "Build, Execution, Deployment > Build Tools > Gradle". In there, you can set the JDK location.

Gradle Settings

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.

Upvotes: 278

charitha amarasinghe
charitha amarasinghe

Reputation: 624

to set the Java version from the android studio terminal write this command on the terminal (MAC)

cammand -> export JAVA_HOME='-- java home path (can get from Preferences-> Build,Execution,Deployement -> Gradle'

example (set java 11)->

export JAVA_HOME='/Applications/jdk-11.0.16.1.jdk/Contents/Home'

then you can check whether is it changed or not using java -version command

Upvotes: 1

Ata Iravani
Ata Iravani

Reputation: 2206

For the latest version (2022.2.1 Patch 2) at this time, The setting has been moved to gradle setting.

So just open the project structure through File > Project Structure, Select SDK Location from left menu, click on Gradle Settings.

Here select the Gradle JDK you want. I would suggest to select the Android Studio Java Home option.

Android Studio Gradle Setting

Upvotes: 5

Matthieu Esnault
Matthieu Esnault

Reputation: 1127

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

Upvotes: 79

user2020898
user2020898

Reputation: 29

  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

Upvotes: 2

Rishabh
Rishabh

Reputation: 1861

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

Upvotes: 29

Francis Bacon
Francis Bacon

Reputation: 4745

Check the JDK you use in Android Studio

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 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)

Upvotes: 8

Jonathan Rosenne
Jonathan Rosenne

Reputation: 2217

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

Upvotes: 3

Vishwa Pratap
Vishwa Pratap

Reputation: 382

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

Upvotes: 3

Lorraine
Lorraine

Reputation: 157

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

Upvotes: 6

Related Questions