Issue
I have tried the answers at here & href="https://stackoverflow.com/questions/68416723/i-am-getting-this-errors-cmdline-tools-component-is-missing-i-have-installed-f">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:
Solution
You can follow below steps in order to ensure proper working of your flutter project: your sdk manager should look something like this:
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)
and make sure every tools must be of same latest version in order to avoid any error as there might be new updates later on.
2. Also make sure to Accept Android Licences by running below command in your cmd:
flutter doctor --android-licenses
if anything above didn't worked 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 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:
This one is for system variable path:
Follow source to learn more about setting the path for java:
Answered By - Abhishek Vishwakarma
Answer Checked By - David Marino (JavaFixing Volunteer)