i3arty
i3arty

Reputation: 71

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!

Upvotes: 3

Views: 13048

Answers (4)

Joukhar
Joukhar

Reputation: 872

the solution in linux ( ubuntu 22.04 lts )

the problem was that android studio has been updated automatically from snap

if u run flutter doctor you will that android studio is not installed

all you have to do is open it and close it

Upvotes: 0

Kiran Stha
Kiran Stha

Reputation: 31

I figured out that after setting the JAVA_HOME variable. You also should check the "Path" variable in the system variables, if you are doing this manually. See if there is Jdk path available, if not add the path including the bin folder in the path also remember do not add the bin folder path while locating in JAVA_HOME variable.

Upvotes: 0

Monu
Monu

Reputation: 714

  1. Please check your environment variables if they contain JAVA_HOME with your JDK path.
  2. Check your flutter path at the environment variable.
  3. Then command it flutter config --android-sdk="/home/user/Android/Sdk" For Linux only
  4. Then command flutter doctor --android-licenses and accept all licenses

Upvotes: 2

i3arty
i3arty

Reputation: 71

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

Upvotes: 4

Related Questions