Как поменять jdk в андроид студио



How to upgrade an Android project to Java 11

I am using the latest Android Studio Arctic Fox 2020.03.01 Canary 8 and AGP 7, and I want to convert my project to use Java 11. Apparently just doing the following does not work as mentioned on https://developer.android.com/studio/preview/features#use-java-11:

I get the following error when I build:

To keep it simple, I’ve been trying this on a Jetpack Compose sample project here: https://github.com/android/compose-samples/tree/main/JetNews

Any thoughts? Thanks guys

7 Answers 7

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

From Android Studio Artic Fox 2020.3.1

Preferences (Settings) -> Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JDK -> Select JDK 11 or download JDK

Before Artic Fox 2020.3.1 Version

I assume you have Java 11 or later installed. Following steps:

File -> Project Structure -> SDK Location -> Change JDK Location to the Java 11 jdk folder

If you are using Mac OS then try to search for that folder in:

Источник

How to change Android Studio default gradle JDK to 11

Getting this message when I click run:

The answers from Error message «Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8» to change the Gradle JDK in settings work. but only for that one project. When I create a new project, Android Studio automatically uses default 1.8 again.

I have 11 available, AS just doesn’t automatically use it. Things I tried: changed the JAVA_HOME env to the location for JDK 11 here, but still get the same error.

Invalid cache /restart a bunch of time does nothing

How to set it once and apply it to all future new projects?

top level build.gradle

4 Answers 4

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

Might seem late, but I fixed mine by just installing the java jdk needed, installed jdk 17 by the way. That’s after downloading it from my browser and installing it. then you could check your java version on your device using; «java —version» command on cmd, then you could just restart your pc and open android studio. then check the jvm of gradlew —version command on terminal in android studio and if it’s updated you are good to go

Multiple Android Studio Installed?

Short Answer:

Just delete the other version and it should fix the problem.

Long answer:

I had two versions of Android Studio installed Android 4.2 and Android Arctic Fox. Both Android Studio had different Gradle JDK version installed.

This is what I was seeing in Arctic Fox Gradle Settings. (Default selection was 1.8)

My theory:

If you notice Gradle JDK is installed under Applications/Android Studio/Content/

It’s my assumption that Gradle Settings page pulls up all the installed Gradle JDK versions. And there is no option to set the default version in Settings page. So the first Gradle version becomes the default.

I don’t know if it is alphabetically sorted or based on Download timestamp.

But I believe it is based on the timestamp. The oldest installed version gets to the top in the list.

Here is a supporting observation. When I deleted Android Studio 4.2 and ctrl+z (Undo) it the list order changed.

Disclaimer:

I could be completely wrong as I don’t have any official doc, link that support this claim. It is just a theory.
And I understand that is is not an ideal solution as deleting old Android Studio may not be the option for everyone.

Источник

How to change JDK location in Android Studio?

When I open my project in Android Studio I see default JDK

I went to settings and tried to change jdk but it didn’t save. The previos path is still showed in Android Studio

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

Should I change something in my gradle.kts file?

4 Answers 4

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

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

To set a java version as default,

You can change File > Project Structure > SDK Location

OR, You can change local.properties files

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

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.

Источник

How to set Java SDK path in AndroidStudio?

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.

10 Answers 10

Trending sort

Trending sort is based off of the default sorting method — by highest score — but it boosts votes that have happened recently, helping to surface more up-to-date answers.

It falls back to sorting by highest score if no posts are trending.

Switch to Trending sort

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:

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.

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.

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.

Источник

How to Set Java SDK Path in Android Studio?

The Java SDK for Android is a sophisticated suite of tools for managing, monitoring, profiling, and debugging Java code written in Android Studio. But sometimes as software is unpredictable you might be caught in an error that Android Studio stopped compiling projects and says that it can’t locate the 1.7.0_21 folder. Well, this is exactly what is referred to as a missing Java SDK Path.

How to Fix the Java SDK Path?

There are several methods that can help you resolve this issue, the ones which have the highest score in fixing this problem are mentioned below:

Method #1: For Android Studio Version 4.2 and Above

Navigate to File > Project Structure > SDK Location. Upon navigating there you will find that a tab named “JDK Location”, select that and then you can set the JDK path for the current project on which you’re working.

Image I. Setting Project SDK location in 4.2 & +

Method #2: For Android Studio Version Below 4.2

Chances are that you might be rocking an older version of Android Studio, if yes then

Navigate to File > Project Structure > [Platform Settings] > SDKs

You’ll then need to either update your current SDK setup to make use of the new directory or create a new directory and then adjust the settings in your project to make use of the new directory. This will make it applicable to the present project.

Method #3: Adding a new SDK to Your Android Studio

Sometimes only updating your SDKs won’t allow you to compile projects just because the SDK has lived its life and requires an update to itself. In that scenario, you’ll need to recreate the configurations from 0.

  1. Navigate to Project Structure > Platform Settings > SDKs and click the “+” button.
  2. Go to your Android SDK folder and select “Choose” on the pop-up.
  3. A new pop-up window will open, asking which SDK and JDK you’d want to use. Select any Android SDK and the JDK 1.7.

Note: Change your Project SDK to the one you just established under Project Structure > Project Settings > Project. The name of the SDK should now include the new Java version that you installed.

Method #4: For the Command Line Enthusiasts

If you want to be a Geek and the above methods are just too much GUI for you, you might want to handle the SDK path using the terminal. In order to achieve that using the command line, follow the below commands in the Android Studio’s Terminal

and just like that, you’ve achieved the desired result

Note: the ‘oldjre‘ here refers to your old JRE path

Method #5: Using the Embedded SDK

If you are on Android Version 3.2 or older then you’ll be having the option of using the embedded JDK & SDK for your project and that is one of the optimal ways you can fix this issue as Android Studio will handle the management of the services in the Backend!

Navigate to File > Project Structure > JDK Location and Checkmark the box saying “Use embedded JDK (recommended)”.

Image II. Checking the Recommended JDK Location

Method #6: Setting and Viewing SDK using the Studio Project Structure

If all the above-mentioned ways didn’t work out for you, the best you can do is to get the SDK path of another Android Studio Project and then providing that path to your particular project (as in Method #1)

Press Ctrl (Command on Mac) + Alt + Shift + S

Then in the SDK Location tab, you will find your SDK Location, just copy it and paste it in the SDK Location as mentioned in Method #1.

Источник

You may also like...

Adblock
detector