Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter development - ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH

So I am following a course from flutter on udemy and I run into this error when I try to run the app on the emulator.

It says "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH." "Please set the JAVA_HOME variable in your environment to match the location of your Java installation. Exception: Gradle task assembleDebug failed with exit code 1"

Also when I run flutter doctor on cmd it says that it found 2 issues, which are those

[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)

X Android license status unknown.
  Run `flutter doctor --android-licenses` to accept the SDK licenses.
  See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

[√] Chrome - develop for the web [!] Android Studio (not installed) <<I have android studio installed so not sure why it says that.

Can anyone help me? I tried looking online but the answers did not help me.

Thank you!

like image 236
i3arty Avatar asked Mar 03 '26 20:03

i3arty


1 Answers

So after like 2 hours of struggling figuring what's wrong I finally came up with what's wrong!!

If anyone has a similar issue try these

  1. Fixing JAVA_HOME - Make sure it's in "System variables" and not user variables -- You can open the command on windows and just paste "setx -m JAVA_HOME C:\Program Files\Java\jdk-16.0.2"

That's if you saved it by default, if it's in different folder just navigate to the folder and copy the location path eg D:\Program Files\Java\jdk-16.0.

  1. When you ask for licenses(flutter doctor --android-licenses) and run into "Exception in thread "main" java.lang.NoClassDefFoundError"

Try going into your Android studio > SDK manager > SDK Tools tab >Downloading android sdk command line tools > Running cmd > "flutter doctor" > flutter doctor --android-licenses > and then accept them all by typing "y" (Before i did not have the licenses, it was some errors)

  1. If you run into issue that when you type "flutter doctor" and have error of "android studio not installed

Go into your command and type "flutter config --android-studio-dir="C:\Program Files\Android\Android Studio"

Thats if you installed it by default

Hope that helps someone who stumbles to similar issues

like image 168
i3arty Avatar answered Mar 05 '26 08:03

i3arty



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!