How to set Java SDK path in AndroidStudio?
Solution 1
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.
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.
Solution 2
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.
Solution 3
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:
- In Project Structure > Platform Settings > SDKs, click the "+" button to add a new SDK.
- In the pop-up, go into your Android SDK folder and click "Choose"
- Another pop-up will appear asking for which SDK and JDK you want to use. Choose any Android SDK and the 1.7 JDK.
- 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.
Solution 4
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.
Solution 5
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...
Related videos on Youtube
Teshan N.
Software Engineer specialised in web application development. Skilled in: PHP, Symfony, JS, CSS, Wordpress, WooCommerce, Python, AutoCAD, SketchUp, Lumion, FL Studio
Updated on July 08, 2022Comments
-
Teshan N. almost 2 years
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.
-
Nux over 7 yearsThis 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.
-
Vintesh over 7 yearsI'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. -
Clocker over 7 yearsThe issue of JDK path resetting because of other warnings within the Project Structure settings can be solved by @Vintesh comment. Great find guys!
-
Tom Zych over 7 yearsAre you answering the question or asking another question?
-
ToolmakerSteve over 5 yearsFYI re @Vintesh 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 pathC:\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. -
Pedro Lobito over 5 yearsYou may have forgotten to invalidate the caches.
-
Amruth A over 3 yearswhere is this settings ?
-
Javier Delgado about 2 yearsThis changes the version for all projects. Can't I have the JDK version by project?
-
Jose Javier Sanahuja almost 2 yearsThanks for the hint of creating a new SDK
-
Ephra almost 2 yearsMy android studio does not have any of those suggested options, is there any other alternative?