admin管理员组

文章数量:1122832

I use android studio ladybug 24.2.1 In this version، GDK v-21 is Build-in how to change JDK for Android Studio from 21 to jdk 17.

JDK for Android toolchain is 17 and Android Studio is 21. I want to use JDK 17 for both of them.

This screenshot shows JDK 21 being used for Android Studio:

I use android studio ladybug 24.2.1 In this version، GDK v-21 is Build-in how to change JDK for Android Studio from 21 to jdk 17.

JDK for Android toolchain is 17 and Android Studio is 21. I want to use JDK 17 for both of them.

This screenshot shows JDK 21 being used for Android Studio:

Share Improve this question edited Nov 22, 2024 at 22:29 dan1st 16.1k16 gold badges88 silver badges125 bronze badges asked Nov 22, 2024 at 11:52 A.HammamA.Hammam 154 bronze badges 1
  • Why do you want to change the JDK Android Studio is running with. Android Studio comes with built-in JDK. I don't think you can change that. usually you only need to change the JDK gradle is running with - is that what you call "JDK for Android toolchain"? – Robert Commented Nov 22, 2024 at 15:19
Add a comment  | 

5 Answers 5

Reset to default 1

Check Installed JDKs, Ensure the desired JDK version is installed.

Open Android Studio Preferences

Open Android Studio. Go to Preferences -> Navigate to JDK Settings

In the Preferences window, go to: Build, Execution, Deployment > Build Tools > Gradle. Change the JDK Path

Under "Gradle JDK," click the dropdown and select your desired JDK version.

I had a similar issue with not being able to set it via studio so the easiest way

  • Download jdk separately.
  • Configure my project to use 17
    • flutter config --jdk-dir yourJDK path
  • Optionally (Some plugins may require) update
    • sourceCompatibility JavaVersion.VERSION_17
    • targetCompatibility JavaVersion.VERSION_17
    • jvmTarget = '17'

To change Android Studio's JDK, follow these steps: 1 Go to File > Project Structure. 2 Select the SDK Location section in the list of the left. 3 Deselect the Use embedded JDK (recommended) option. 4 Enter the absolute path of your installed JDK in the text box 5 Digi also recommends you lower the default memory setting for Gradle (org.gradle.jvmargs property): ◦ Create a file called Gradle. Properties in the root of your project The reference I used is the website of my university.

If you use version manager like fvm,

  1. Make sure your desired version set as global

  2. do this command to change desired JDK version

    flutter config --jdk-dir "C:\Program Files\Java\jdk-17.0.4"

Restart IDE or terminal, Happy coding

Here's what I did on my machine...

You can download Java 17 SDK based on your machine. Here's the link

After you download and install it.

Please go to your Android Studio's File > Project Structure...

Then select your installed Java SDK by this way:

Note: You can also verify there if you properly selected the corresponding Java SDK.

After selecting, click apply, and then ok.

Please consider doing File > Invalidate Caches...

After doing these things. Execute flutter doctor -v again.

Make sure you set the proper PATH and JAVA_HOME in your ENVIRONMENT VARIABLES. Here's what I set for PATH: C:\Program Files\Java\jdk-17\bin and for JAVA HOME: C:\Program Files\Java\jdk-17 it should be added in your system variables section.

For instant checking of your PATH and JAVA_HOME setup,

In Windows, open your command prompt, then execute these commands:

for checking your PATH
where java
for checking your JAVA_HOME
echo %JAVA_HOME%

UPDATE

Here's the related answer to the OP's case: you may please visit this answer

I hope it helps!

本文标签: javahow to change JDK for Android Studio from 21 to jdk 17Stack Overflow