Reputation: 71
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
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
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
Reputation: 714
flutter config --android-sdk="/home/user/Android/Sdk"
For Linux onlyflutter doctor --android-licenses
and accept all licensesUpvotes: 2
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
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.
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)
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