How to Specify the Jdk Version in Android Studio

How to specify the JDK version in Android Studio?

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.

Project Structure Dialog

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.

How to find out the embedded JDK version of Android Studio?

The embedded JDK is included in the Android Studio install. If you open the folder where you installed Android Studio, you'll see a jre folder in it:

Image showing the JRE folder in the Android Studio installation folder

Inside the folder there is a file called THIRD_PARTY_README in which the second sentence says:

%% This notice is provided with respect to ASM Bytecode Manipulation 
Framework v5.0.3, which may be included with JRE 8, and JDK 8, and
OpenJDK 8.

I'm using Android Studio 3.0, in which the embedded JDK version is 8. To find the version in any later version though, go to [SDK_INSTALL_ROOT]/jre/ and find THIRD_PARTY_README


THIRD_PARTY_README is in my system defined as a file and not a txt file. You can open it in Notepad, Notepad++ or any other text editor. The content is plain text. You can also look for a file called release, which contains similar information about versions.

How to set Java SDK path in AndroidStudio?

Up to Android Studio 4.2

Go to File > Project Structure > SDK Location. The third field is "JDK Location" where you can set it. This will set it for the current project.

Sample Image

To set the default for new projects, go to File > Other Settings > Default Project Structure > SDK Location and set the "JDK Location".

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

Older Versions

Go to File > Project Structure > [Platform Settings] > SDKs. You'll need to either update you current SDK configuration to use the new directory, or define a new one and then change your project's settings to use the new one. This will set it for the current project.

To set the default for new projects, go to File > Other Settings > Structure for New Projects > [Platform Settings] > SDKs and set the SDK to use when creating a new project.

How to change JDK location in Android Studio?

java -version

Would help us to know to the current java version. To switch between the installed java versions, update-java-alternatives would help.

To list all java versions installed in the device

update-java-alternatives --list

To set a java version as default,

sudo update-java-alternatives --set <path_to_installed_java_version>

How to set Java JDK path in Android Studio Arctic Fox, Bumblebee, etc.?

  1. Go to File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle
  2. Choose JDK folder for Gradle JDK field
  3. Apply changes

Sample Image

NB: If you haven't Java environment on your PC, go to https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html and download Java jdk for your platform.

NB2: It's JDK for your Gradle, not for your source code compiler (!)

How do I tell Gradle to use specific JDK version?

Two ways

  1. In gradle.properties in the .gradle directory in your HOME_DIRECTORY set org.gradle.java.home=/path_to_jdk_directory

or:


  1. In your build.gradle

     compileJava.options.fork = true
    compileJava.options.forkOptions.executable = '/path_to_javac'


Related Topics



Leave a reply



Submit