Ashfaq
Ashfaq

Reputation: 6493

I am getting error "cmdline-tools component is missing" after installing Flutter and Android Studio... I added the Android SDK. How can I solve them?

Android toolchain - I develop for Android devices (Android SDK version 30.0.3):

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.

Upvotes: 649

Views: 676999

Answers (26)

pandagoespoop
pandagoespoop

Reputation: 109

For anyone on Linux, I've wrote a script to download and setup the android SDK and flutter. I was getting errors with flutter doctor being unable to find the sdkmanager and cmdline-tools and this fixed it.

Let's see how long until they make a change to break this script lol.

See the github repo for possible updates to this :).

https://github.com/sslater11/flutter-linux-installer-with-android-studio/

#!/bin/bash
# This script is licensed under the BSD 3-Clause License.

android_backup_path=`mktemp -u -t Android.backup.XXXXXXX -p "$HOME/"`
flutter_backup_path=`mktemp -u -t flutter.backup.XXXXXXX -p "$HOME/"`


message_download_android_studio="Before running this, please download android studio ladybug from here\nhttps://developer.android.com/studio\nAnd then extract it to $HOME/android-studio-ladybug/\n\nPress enter when done and the script will setup flutter for android development"
whiptail --title "Information" --msgbox "$message_download_android_studio" 0 0
whiptail --title "Information" --msgbox "You will be asked to accept loads of licenses and it's all google's fault..." 0 0

if whiptail --title "Confirmation" --yesno "Warning: You are about to move files.\nBacking up old android($HOME/Android) to $android_backup_path\nDo you want to continue?" 0 0; then
    echo "User chose to continue."
else
    echo "User chose to cancel."
    exit
fi

echo "Backing up old android($HOME/Android) to $android_backup_path"
mv "$HOME/Android" "$android_backup_path"

echo "Creating new folder $HOME/Android"
mkdir -p "$HOME/Android/Sdk/"
cd "$HOME/Android/Sdk/"


echo "Downloading commandlinetools and extracting."
wget https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip

# Create the cmdline-tools folder
# and also make a folder called 'latest' inside cmdline-tools, which is the exact same as cmdline-tools
unzip commandlinetools-linux-11076708_latest.zip
mkdir cmdline-tools/latest
unzip commandlinetools-linux-11076708_latest.zip -d cmdline-tools/latest
mv cmdline-tools/latest/cmdline-tools/* cmdline-tools/latest/ 
rm -rf cmdline-tools/latest/cmdline-tools/

cd cmdline-tools/bin

./sdkmanager --sdk_root="$HOME/Android/Sdk/" --install "build-tools;36.0.0-rc3"
./sdkmanager --sdk_root="$HOME/Android/Sdk/" --install "platforms;android-35"
./sdkmanager --sdk_root="$HOME/Android/Sdk/" --install "platform-tools"
./sdkmanager --sdk_root="$HOME/Android/Sdk/" --install "emulator"
./sdkmanager --sdk_root="$HOME/Android/Sdk/" --install "cmdline-tools;latest"
./sdkmanager --sdk_root="$HOME/Android/Sdk/" --licenses # Ask user to accept all licenses

cd ../../

if whiptail --title "Confirmation" --yesno "Warning: You are about to move files.\nBacking up old flutter($HOME/flutter) to $flutter_backup_path\nDo you want to continue?" 0 0; then
    echo "User chose to continue."
else
    echo "User chose to cancel."
    exit
fi
echo "Downloading flutter"
wget https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.27.1-stable.tar.xz

echo
echo "Backing up old flutter($HOME/flutter) to $flutter_backup_path"
mv "$HOME/flutter" "$flutter_backup_path"
tar -v -x -f "flutter_linux_3.27.1-stable.tar.xz"
mv "flutter" "$HOME/"

cd "$HOME/flutter/bin"

echo
echo If this freezes, press enter. It should take less than a second.
./flutter --disable-analytics
echo If this freezes, press enter. It should take less than a second.
./dart --disable-analytics
echo If this freezes, press enter. It should take less than a second.
./flutter config --android-sdk="$HOME/Android/Sdk"
./flutter config --android-studio-dir="$HOME/android-studio-ladybug/"

echo
echo
echo "--------------------"
if whiptail --title "Confirmation" --yesno "Would you like to add flutter to your \$PATH variable?\nThis will be appended to your ~/.bash_profile\nYou will need to log out and back in for changes to take place.\nAfterwards you can use the 'flutter' command in a bash shell." 0 0; then
    echo "User chose to continue."
    echo 'export PATH="$HOME/flutter/bin:$PATH"' >> ~/.bash_profile
    if [ -e "/usr/bin/chromium" ]; then
        echo 'export CHROME_EXECUTABLE="/usr/bin/chromium"' >> ~/.bash_profile
    elif [ -e "/snap/bin/chromium" ]; then
        echo 'export CHROME_EXECUTABLE="/snap/bin/chromium"' >> ~/.bash_profile
    fi
    fish_add_path "$HOME/flutter/bin/"
else
    echo "Please add flutter to your \$PATH variable to make it executable using the 'flutter' command."
    echo "For bash shell type this command to add it to your bash path permanently."
    echo "echo 'export PATH=\"\$HOME/flutter/bin:\$PATH\"' >> ~/.bash_profile"
    echo
    echo "or to add it for just this bash session"
    echo 'export PATH="$HOME/flutter/bin:$PATH"'
    echo
    echo "For fish shell, type this command"
    echo "fish_add_path \"\$HOME/flutter/bin/\""
    if [ -e "/usr/bin/chromium" ]; then
        echo
        echo "Set the location for chromium for web develoment."
        echo "echo 'export CHROME_EXECUTABLE=\"/usr/bin/chromium\"' >> ~/.bash_profile"
        echo "or"
        echo "export CHROME_EXECUTABLE=\"/usr/bin/chromium\""
    elif [ -e "/snap/bin/chromium" ]; then
        echo
        echo "Set the location for chromium for web develoment."
        echo "echo 'export CHROME_EXECUTABLE=\"/snap/bin/chromium\"' >> ~/.bash_profile"
        echo "or"
        echo "export CHROME_EXECUTABLE=\"/snap/bin/chromium\""
    fi
fi

echo "Finally run in a terminal the command"
echo "flutter doctor"
echo "or"
echo "$HOME/flutter/bin/flutter doctor"
echo
echo "for a more detailed output run"
echo "$HOME/flutter/bin/flutter doctor -v"
echo
echo "If it didn't work, you may need to logout and back in for changes to take effect."
echo "A quick way to test if you need to login/out is to run theese commands:"
echo "bash --login"
echo "$HOME/flutter/bin/flutter doctor"
echo
echo "Hopefully it'll work for you :)"

#Other environment variable that may be useful to someone :).
## for bash shell paste this into the terminal.
#export PATH=$PATH:"$HOME/flutter/flutter/bin/"
#export PATH=$PATH:"$HOME/Android/Sdk/platform-tools"
#export PATH=$PATH:"$HOME/Android/Sdk/cmdline-tools/latest/bin/"
#export PATH=$PATH:"$HOME/Android/Sdk/build-tools/36.0.0-rc3/"
#export PATH=$PATH:"$HOME/Android/Sdk/emulator/bin64/"

## for fish shell paste this into the terminal.
#fish_add_path -g -p "$HOME/Android/Sdk/platform-tools"
#fish_add_path -g -p "$HOME/Android/Sdk/cmdline-tools/latest/bin/"
#fish_add_path -g -p "$HOME/Android/Sdk/build-tools/36.0.0-rc3/"
#fish_add_path -g -p "$HOME/Android/Sdk/emulator/bin64/"

Upvotes: 0

Felipe Carvalho
Felipe Carvalho

Reputation: 13166

The solution for me was opening Android Studio and going to SDK Manager, switch to the SDK Tools tab and check Android SDK Command-line Tools (latest).

enter image description here

Don't forget to add to your PATH the tools and platform-tools folder that are inside your SDK.

Upvotes: 1297

navalega0109
navalega0109

Reputation: 402

Goto:

  1. Tool->SDK Manager and Apply SDK command line toolkit.

enter image description here

Upvotes: 2

ankushlokhande
ankushlokhande

Reputation: 1900

Install the Android SDK Command-line Tools:

  • For the updated version of Android Studio, the Setting is here:
Settings > Languages & Framework > Android SDK > SDK Tools (TAB)

Android SDK Command-line Tools

  • For older version:
Settings > Appearance & Behavior > System Settings > Android SDK > SDK Tools (TAB)

Android SDK Command-line Tools

Upvotes: 3

Md Masud
Md Masud

Reputation: 2711

  1. Open SDK Manager from your Android Studio.

  2. You can find SDK manager from the menubar → ToolsSDK Manager or use the icon. As in the picture.

    Enter image description here

  3. SDK Tools tab

  4. Check Android SDK Command Line Tools as in the picture

  5. Apply

    Enter image description here

  6. Then again run flutter doctor in your terminal.

Upvotes: 126

sudheer nunna
sudheer nunna

Reputation: 1719

I executed the below command to fix the issue on Mac:

/Users/<user username>/Library/Android/sdk/tools/bin/sdkmanager --install "cmdline-tools;latest"

Upvotes: 0

Norman
Norman

Reputation: 3167

Since my Android Studio starting screen looks different from the answers above, I want to share my solution:

An image of the 'Welcome to Android Studio' screen. An arrow highlights the "More Actions" dropdown menu on the bottom of this screen, and a second arrow highlights the "SDK Manager" option within the dropdown menu.

  • Open Android Studio and click on 'more actions' on the welcome screen.

  • Click on 'SDK Manager'

    An image of the "Preferences" window within Android Studio. "Android SDK" is selected on the left, then on this settings page, "SK Tools is selected from a top-bar menu. The item called "Android SDK Command-line Tools (latest)" is checked, and changes are applied.

  • In the 'Preferences' window go to the 'SDK Tools' tab

  • Select the 'Android SDK Command-line Tools (latest)' checkbox.

  • Click on Apply.

Upvotes: 233

Ashish Sahu
Ashish Sahu

Reputation: 1558

For macOS users

If you already have Android Studio installed, simply run:

flutter config --android-sdk "/Users/$USER/Library/Android/sdk" & flutter doctor --android-licenses

Upvotes: 3

Badrul
Badrul

Reputation: 459

On Windows I did two things to resolve it.

  1. Launched Android Studio > More Actions > SDK Manager>SDK Tools and ticked and applied Android SKD Command line tools

  2. Entered flutter config --android-sdk C:\Users\xxx\AppData\Local\Android\Sdk into the command line. The path came from the top of the screen in step 1.

Upvotes: 3

Mstrdav
Mstrdav

Reputation: 121

If you have already downloaded cmdline-tools and the Android SDK, make sure Flutter isn't looking in the wrong directory with:

flutter config --android-sdk=""

Upvotes: 12

Rokas Rudzianskas
Rokas Rudzianskas

Reputation: 998

For me, running this command worked perfectly:

flutter config --android-sdk /path/to/your/sdk

Upvotes: 2

sidharth vijayakumar
sidharth vijayakumar

Reputation: 1571

I installed the Android SDK platform tool from Android Studio. This helped me to resolve this error.

Error before installation

Installed platform tool from Android Studio

After installation of Platform tools

Upvotes: 5

Dinith
Dinith

Reputation: 1039

You have to install Android SDK Command-line Tools. To do that, invoke the menu command FileSettingsAndroid SDK and download the latest.

You must choose Android SDK on the left side of the Settings window. It’s under Appearance & BehaviorSystem Settings.

Upvotes: 4

Manash J. Barman
Manash J. Barman

Reputation: 571

For Windows users

If you still see the same error even after your build tools, tools are installed and added to the user/system path variable, and maybe your sdkmanager location is really not found

  • Just type in
flutter config --android-sdk "C:\Users\{Your_User_Name}\AppData\Local\Android\Sdk" # (Default SDK location)
  • Add the path inside "" to where your Android SDK folder is located

  • Then you can run the licenses to verify any license which is not approved.

This worked for me.

Upvotes: 57

Venkatesh Muniyandi
Venkatesh Muniyandi

Reputation: 5640

This is for Windows: If you are still facing the issue even after installing the "Android SDK Command-line Tools(latest)" thru Android Studio -> Settings->Appearance & Behavior -> Systems Settings -> Android SDK -> SDK Tools, You need to configure the flutter for Android SDK Path (Not the environment variable path).

Android SDK Will be installed under Program files e.g. (C:\Program Files (x86)\Android\android-sdk). If not this location, find out the location where it is installed and go to the bin folder (C:\Program Files (x86)\Android\android-sdk\cmdline-tools\7.0\bin) and run

flutter config --android-sdk "C:\Program Files (x86)\Android\android-sdk"

After this run flutter doctor, now this issue should be resolved.

Upvotes: 2

Kaloglu
Kaloglu

Reputation: 1761

For macOS users:

flutter config --android-sdk "/Users/{YOUR_USER_NAME}/Library/Android/sdk"

Then

flutter doctor --android-licenses

Type "y" for all stops.

Upvotes: 18

Sharon A
Sharon A

Reputation: 2645

Your Android SDK version requires an update.

Open Android Studio → click Android Studio on the top bar → PreferencesAppearance & behavior (click to open the dropdown) → System Settings (click to open the dropdown) → Android SDKSDK Tools (tab).

Check Android SDK Command-line Tools (latest)Apply → click OK. Once the update has finished, run flutter doctor.

Screenshot of the Appearance & Behavior menu

Upvotes: 30

Enes Karaosman
Enes Karaosman

Reputation: 2067

For macOS, I ran this command;

cd ~/Library/Android/sdk/tools/bin
./sdkmanager --install "cmdline-tools;latest"

Then when I ran the flutter doctor command again, it confirmed that the problem was solved.

Upvotes: 25

jahidul islam
jahidul islam

Reputation: 21

If you have installed the latest cmd-line tools from Android Studio, but it still gives the error, then you should do the following.

If you have installed the Android SDK to a custom directory, then you need to copy the path of your SDK folder. Then you have to go to the edit environment variable, click New give a variable name: ANDROID_SDK_ROOT. And a variable value: path of your SDK folder. Click OK.

In the older version of Flutter, this error came with the solution (creating ANDROID_SDK_ROOT), but in the new versions it does not show that.

Upvotes: 2

Amin Arshadinia
Amin Arshadinia

Reputation: 306

I solved this problem on Windows 10 with the following actions:

  1. Run the following command in a Windows command prompt or Flutter console:

    flutter config --android-sdk "C:\Users\'your computer name' AppData\Local\Android\Sdk"
    

    (you may need to find and enter your own SDK path)

    The Android SDK location could be found in the Android Studio application* → Appearance & BehaviorSystem SettingsAndroid SDK

  2. Open your Android Studio, and then → FileSettingsAppearance & BehaviorSystem SettingsAndroid SDKSDK Tools → download Android SDK Command-line Tools (latest) and you are good to go.

Upvotes: 10

pola wahba
pola wahba

Reputation: 61

For Linux (Ubuntu)

Just copy this command in your terminal and change 'your user name' with your user name without spaces:

/home/your user name/Android/Sdk/tools/bin/sdkmanager --install "cmdline-tools;latest"

Upvotes: 5

jnsnsml
jnsnsml

Reputation: 1440

Android SDK Manager screenshot on Windows

Enter image description here

Please see the attached screenshot for installing tools from SDK Manager.

Upvotes: 143

Md. Shahariar Hossen
Md. Shahariar Hossen

Reputation: 1715

Enter image description here

Easiest solution:

  • Open Android Studio and click settings in the upper left corner of Android studio.
  • Search for "SDK tools" in the search box.
  • From the SDK tools just check the Android SDK Platform Tools.
  • Run flutter doctor to verify. You can also restart Android Studio if you want.
    I hope the problem will be solved.

Upvotes: 16

Prajeet Naga
Prajeet Naga

Reputation: 233

If you are a Mac user, just open your terminal and paste:

cd Library/Android/sdk/tools/bin./sdkmanager --install "cmdline-tools;latest"

And hit Enter.

This command will install the latest version of cmdline-tools.

Then, run flutter doctor, and the error will be gone.

Upvotes: 5

jqgsninimo
jqgsninimo

Reputation: 7038

My solution process is as follows:

  1. ~/Library/Android/sdk/tools/bin/sdkmanager --install "cmdline-tools;latest"

    Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
        at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
        at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
        at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
    Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
        ... 5 more
    
  2. Install Android SDK Command-line Tools in Android Studio:

    PreferencesAppearance & BehaviorSystem SettingsAndroid SDKSDK ToolsAndroid SDK Command-line Tools (latest)

  3. flutter doctor

    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, 2.5.0, on macOS 11.5.2 20G95 darwin-x64, locale zh-Hans-CN)
    [✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    [✓] Xcode - develop for iOS and macOS
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 2020.3)
    [✓] IntelliJ IDEA Ultimate Edition (version 2021.2)
    [✓] IntelliJ IDEA Ultimate Edition (version 2021.2)
    [✓] Connected device (2 available)
    
    • No issues found!
    

Upvotes: 63

regina_fallangi
regina_fallangi

Reputation: 2198

If what flutter doctor said was something like:

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at /Users/<admin>/Library/Android/sdk
✗ cmdline-tools component is missing
  Run `path/to/sdkmanager --install "cmdline-tools;latest"`

The path/to/sdkmanager for me was:

/Users/<user>/Library/Android/sdk/tools/bin/sdkmanager

So what solved the whole thing for me was running:

/Users/<user>/Library/Android/sdk/tools/bin/sdkmanager --install "cmdline-tools;latest"

Upvotes: 28

Related Questions