How to set Java SDK path in AndroidStudio?
Asked Answered
E

10

158

I had Java 1.7.0_21 installed and I installed 1.7.0_45 today after uninstalling the previous version. Now Android Studio has stopped compiling projects and says that it cant locate the 1.7.0_21 folder. How can I set the new path for Java SDK? I have changed the environment variables also but didn't work.

Evvoia answered 26/10, 2013 at 15:57 Comment(0)
D
279

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.

enter image description here

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.

Donica answered 26/10, 2013 at 16:38 Comment(7)
This might not work if you have any errors with settings. I had space in SDK path and was not able to change JDK path until I changed SDK path.Bourguiba
I'd a strange issue, I was trying to change JDK path using this only but I was keep resetting to it's default. If someone is facing the same issue, then find your path configuration in file C:\Users\<YOUR_USER_NAME>\.AndroidStudio2.1\config\options\jdk.table.xml & update all occurrence of old path to new path & you will be good to go.Fagan
The issue of JDK path resetting because of other warnings within the Project Structure settings can be solved by @Fagan comment. Great find guys!Larena
FYI re @Fagan comment, as of Android Studio 3.2, under Windows 10, after a NEW install (not importing from an older version), the value to change is line 7 of jdk.table.xml, which on my default installation reads <homePath value="$APPLICATION_HOME_DIR$/jre" />. $APPLICATION_HOME_DIR$/jre corresponds to path C:\Program Files\Android\Android Studio\jre. In the corresponding GUI via File > Project Structure ..., "Use embedded jdk" is checked, and that full path is shown.Excitability
This changes the version for all projects. Can't I have the JDK version by project?Gintz
My android studio does not have any of those suggested options, is there any other alternative?Radiolocation
I gave the same issue as @Ephra. I am using Android Studio Electric Eel and the Build Tools > Gradle page only has a category "General settings" where you can change the "Gradle user home" and Generate *.iml files for modules imported by Gradle. Nothing else.Marcusmarcy
I
35

Go to File> Project Structure (or press Ctrl+Alt+Shift+S), A popup will open now go to SDK Location Tab you will find JDK Location there refer this image to be more clear. enter image description here

Intractable answered 1/9, 2016 at 10:44 Comment(0)
H
13

If you are using new android studio 2021+ then you can find or update JDK settings by navigating to

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

on windows

Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle

on Mac

enter image description here

Hackman answered 22/7, 2022 at 9:32 Comment(1)
The section under "Gradle Projects" does not show for me. I am on a flutter projectDuran
P
10

I tried updating all of my SDKs by just going into the Project Structure > Platform Settings > SDKs and changing the Java SDK, but that didn't work, so I had to recreate the configurations from scratch.

Here's how to create your SDKs with the latest Java:

  1. In Project Structure > Platform Settings > SDKs, click the "+" button to add a new SDK.
  2. In the pop-up, go into your Android SDK folder and click "Choose"
  3. Another pop-up will appear asking for which SDK and JDK you want to use. Choose any Android SDK and the 1.7 JDK.
  4. Go to Project Structure > Project Settings > Project and change your Project SDK to the one you just created. You should see the name of the SDK contain the new Java version that you installed.
Pentose answered 30/3, 2014 at 1:13 Comment(0)
G
9

And now this is located in Gradle settings: enter image description here

Gertiegertrud answered 12/10, 2021 at 20:16 Comment(0)
D
8
C:\Program Files\Android\Android Studio\jre\bin>java -version
openjdk version "1.8.0_76-release"
OpenJDK Runtime Environment (build 1.8.0_76-release-b03)
OpenJDK 64-Bit Server VM (build 25.76-b03, mixed mode)

Somehow the Studio installer would install another version under:

C:\Program Files\Android\Android Studio\jre\jre\bin>java -version
openjdk version "1.8.0_76-release"
OpenJDK Runtime Environment (build 1.8.0_76-release-b03)
OpenJDK 64-Bit Server VM (build 25.76-b03, mixed mode)

where the latest version was installed the Java DevKit installer in:

C:\Program Files\Java\jre1.8.0_121\bin>java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Need to clean up the Android Studio so it would use the proper latest 1.8.0 versions.

According to How to set Java SDK path in AndroidStudio? one could override with a specific JDK but when I renamed

C:\Program Files\Android\Android Studio\jre\jre\

to:

C:\Program Files\Android\Android Studio\jre\oldjre\

And restarted Android Studio, it would complain that the jre was invalid. When I tried to aecify an JDK to pick the one in C:\Program Files\Java\jre1.8.0_121\bin or:

C:\Program Files\Java\jre1.8.0_121\

It said that these folders are invalid. So I guess that the embedded version must have some special purpose.

Donatelli answered 3/2, 2017 at 23:5 Comment(2)
Are you answering the question or asking another question?Furness
You may have forgotten to invalidate the caches.Fraenum
T
7

This problem arises due to incompatible JDK version. Download and install latest JDK(currently its 8) from java official site in case you are using previous versions. Then in Android Studio go to File->Project Structure->SDK location -> JDK location and set it to 'C:\Program Files\Java\jdk1.8.0_121' (Default location of JDK). Gradle sync your project and you are all set...

Townsfolk answered 20/3, 2017 at 14:30 Comment(0)
K
5

1) File >>> Project Structure OR press Ctrl+Alt+Shift+S

2) In SDK Location Tab you will find SDK Location:

enter image description here

3) Change your Project SDK location to the one you have installed

4) Sync your project

Kwangtung answered 26/10, 2017 at 17:31 Comment(0)
Q
2

Go to File>Project Structure>JDK location: Here, you have to set the directory path exactly same, in which you have installed the java version. Also, you have to mention the paths of SDK for project run on emulator successfully.

Why This Problem Occurs: It is due to the unsynchronized java version directory that should be available to Android Studio for java code compilance.

Quantity answered 14/6, 2019 at 19:41 Comment(0)
A
0

Click "use embedded JDK" on version Android Studio 3.2.1

click this box

Amputee answered 29/10, 2018 at 1:59 Comment(2)
where is this settings ?Luthuli
search sdk inside setting optionAfterbrain

© 2022 - 2024 — McMap. All rights reserved.