How to change JDK location in Android Studio?

Viewed 4254

When I open my project in Android Studio I see default JDK https://i.stack.imgur.com/XP8HN.png

I went to settings and tried to change jdk but it didn't save. The previos path is still showed in Android Studio enter image description here

I saw other threads, one of my path doesn't contains s whitespace.

Should I change something in my gradle.kts file?

4 Answers

You can change File > Project Structure > SDK Location

enter image description here

OR, You can change local.properties files

Sample:

sdk.dir=D\:\\Sdk
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>

The built-in JRE is located in the Android Studio installation directory:

.../AndroidStudio...<bla-bla>/jre/

You can temporarily remove this 'jre' directory (or archive)

Launch Android Studio, open any project.

After that, an error message will appear that Android Studio default JDK was not found, and a dialog for selecting it will appear.

There you can select any of your JDKs, which will become the Android Studio default JDK.

All new projects will be created using it.

After that, do not forget to return the JRE directory in the Android Studio installation directory from the archive to its place.

Another way (according to Android Feng Shui)

There are also special environment variables for Android Studio:

STUDIO_JDK - Sets the location of the JDK with which to run Android Studio. When you launch the IDE, it checks the STUDIO_JDK, JDK_HOME, and JAVA_HOME environment variables in that order.

STUDIO_GRADLE_JDK - Sets the location of the JDK that Android Studio uses to start the Gradle daemon. When you launch the IDE, it first checks STUDIO_GRADLE_JDK. If STUDIO_GRADLE_JDK is not defined, the IDE uses the value set in the Project Structure dialog.

Android user guide

In AndroidStudio2020.3.1, I couldn't set the 'default JDK' Settings.I found the JDK XML Settings for AndroidStudio using the "grep" command.It's located in 'C:\Users\Palmer\AppData\Roaming\Google\AndroidStudio2020.3\options\jdk.table.xml'in Windows. I delete it. And the SDK initialization screen appears. SDK initializationThe next step is to initialize the AndroidStudio. Or simply change the default JDK,Modify the XML file to change the JDK versionjdk version

Related