32

I have tried the answers at here & here to no avail.

After installing Android Studio & Flutter on Windows 10, when I run flutter doctor, I get the following:

[√] Flutter (Channel stable, 2.5.0, on Microsoft Windows [Version 10.0.19043.1202], locale en-US)
[X] Android toolchain - develop for Android devices
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
[√] Chrome - develop for the web
[√] Android Studio (version 2020.3)
[√] VS Code (version 1.60.0)
[√] Connected device (2 available)

Opening Android Studio > SDK Manager > Android SDK > SDK Tools uninstalling and re-installing Android SDK Command-line Tools (latest) has no effect.

I have also added <pathToSDK>\tools\bin, <pathToSDK>\platform-tools\, and <pathToSDK>\cmdline-tools\latest\bin to the user PATH environment variables.

Following the flutter instructions and running <pathToSDKManager> --install "cmdline-tools;latest" (Which for me is located in <pathToSDK>\cmdline-tools\latest\bin) results with:

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.

I haven't been able to find any documentation on this other than that I need to install some version on Java and add it to my path. The https://flutter.dev/docs/get-started/install/windows page mentions "Make sure that you have a version of Java 8 installed and that your JAVA_HOME environment variable is set to the JDK’s folder." and then states "Android Studio versions 2.2 and higher come with a JDK, so this should already be done." but doesn't elaborate further.

Opening Android Studio and going to File > Project Structure > Project > Project SDK I can see that Android Studio already recognized several versions of Java installed:

enter image description here

Jhon Piper
  • 513
  • 2
  • 8
  • 21

4 Answers4

78

You can follow the below steps in order to ensure proper working of your flutter project:

Your sdk manager should look something like this:

enter image description here

1. Installing Android SDK Command-line Tools in Android Studio:

Preferences > Appearance & Behavior > System Settings > Android SDK > SDK Tools >

Install these 3 tools:

  • Android SDK Command-line Tools (latest)
  • Android SDK Build Tools 31
  • Android SDK Platform tools (latest version 31)

Make sure every tool is the same latest version in order to avoid any errors as there might be new updates later on.

  1. Also make sure to Accept Android Licences by running below command in your cmd:
flutter doctor --android-licenses

If anything above didn't work out make sure you have set the proper JDK/JRE locations in environment variables in system settings of windows:

Add below path in your System environment path variable for user variable as well as your system variable:

 C:\Program Files\Java\jdkXXXXX\bin 

Here, XXX is your version, and this should be added in your sys var and user both

C:\Users\Neha\AppData\Local\Android\Sdk\tools
C:\Users\Neha\AppData\Local\Android\Sdk\build-tools
C:\Users\Neha\AppData\Local\Android\Sdk\platform-tools

The above three paths should be added in your user variable path. Check the two screenshots attached below for proper path settings. I have added android studio's tools path also so do that as I have done in screenshot.

This one is for user variable path:

enter image description here

This one is for system variable path:

enter image description here

Follow source to learn more about setting the path for java.

Spevacus
  • 584
  • 2
  • 13
  • 23
Mithson
  • 1,554
  • 13
  • 33
  • I've tried all those steps to no avail, something else appears to be wrong that isn't the Command Line Tools. – Jhon Piper Sep 13 '21 at 22:09
  • I had that same issue which you have of java JDK/JRE problem but it resolved after properly updating my tools as to work with lints in flutter cmdline tools and other things needs to be updated too if you have any deprecated lib then this might be the cause or you check if don't have two JDK installed(one might be of android studio and second one might be of your custom installed) and the incompatible one is in use now. It happens just give it a double check. – Mithson Sep 14 '21 at 12:33
  • There appears to be no change after reinstalling all the tools in the `SDK Tools` menu. I've also tried all the options under `Project SDK`. This is a fresh install so it shouldn't have any deprecated dependencies. Is there anything else I should try? – Jhon Piper Sep 14 '21 at 17:05
  • did this issue arrived just after updating to flutter 2.5 or anything else? – Mithson Sep 14 '21 at 17:08
  • check out my answer I have just updated it now and try those if `SDK tools` isnt causing the problem then the most probable cause would be java location they would have been misconfigured – Mithson Sep 14 '21 at 17:16
  • I've just done a full reinstallation of Android Studio and JDK, to be clear `JAVA_HOME` should be a system variable and should be `C:\Program Files\Java\jdkxxx` while `JRE_HOME` should be `C:\Program Files\Android\Android Studio\jre` correct? – Jhon Piper Sep 17 '21 at 23:27
  • Hey @JhonPiper try adding the locations which I have added now in my answer – Mithson Sep 18 '21 at 07:32
  • 1
    seeing just the Android Studio settings screenshot helped a lot. Thanks a million – leipzy Nov 05 '21 at 09:42
  • 1
    Well explained, it resolved my issue – Kishor Patidar Feb 22 '22 at 08:41
0

In the screen you've shown, just use "Android Studio default JDK" (or any other JDK 11).

Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK.

You'd also need to setup the same path as JAVA_HOME environmental variable, as well as ANDROID_HOME. In Windows, these can be added below Settings > Advanced System Settings > Environmental Variables. Flutter needs these set up to find the CLI tools ... and the problem might not be the CLI tools themselves, but that it doesn't know about the Java SDK or Android SDK at all.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • I've set the Android SDK to "Android Studio default JDK". `Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK` already points to a working copy of Gradle at `Users\\.gradle`, does it need to be something else? I've also installed Java JRE, and it is set up as `JAVA_HOME` in my system path variables and it appears to have been excepted by Flutter (See https://stackoverflow.com/a/69111664/12352707 for details). Which directory should `ANDROID_HOME` point towards? Should is be a user or system variable? – Jhon Piper Sep 12 '21 at 20:53
0

If you are installing Flutter without Android Studio. Run this command in your Android/bin folder directory where you have your sdkmanager.bat file. In my case its C:\Android\bin>. type this command

sdkmanager.bat --install "cmdline-tools;latest --sdk_root=../

This worked for me and I hope it will work for you too.

Vicky
  • 11
0

If you have installed Flutter without Android Studio. Run this command in your Android/bin folder directory where you have your sdkmanager.bat file. In my case its C:\Android\bin>

sdkmanager.bat "cmdline-tools;latest" --sdk_root=../