Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to change the Java version shown in the flutter doctor command?

I initially installed Java version 21, but faced compatibility issues while working on a Flutter project. So, I downgraded to Java 17 to resolve these issues. After the downgrade, I verified that Java 17 is correctly installed by running java --version, and it shows version 17 everywhere else.

└─ ❯ java --version
java 17.0.12 2024-07-16 LTS
Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.12+8-LTS-286, mixed mode, sharing)

However, when I run flutter doctor, it still detects Java version 21.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\Users\Lakshan\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    • All Android licenses accepted.

I've tried restarting my system and checking environment variables, but the issue persists. Why does flutter doctor still show Java 21, and how can I fix it to properly recognize Java 17?

like image 762
Lakshan Rukantha Avatar asked Oct 23 '25 12:10

Lakshan Rukantha


1 Answers

If your JAVA_HOME is set properly, you can use flutter config --jdk-dir=$JAVA_HOME to set your JAVA_HOME as the java directory for Android studio.

if the java path is something else, you can configure JAVA_HOME and then follow the above step OR you can run the following command flutter config --jdk-dir=PATH_TO_JAVA

like image 67
albert Avatar answered Oct 26 '25 03:10

albert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!