Android SDK "cmdline-tools component is missing" Error
When setting up Flutter development with Android Studio, many developers encounter the error message: "cmdline-tools component is missing." This error typically appears when running flutter doctor
and indicates that the Android SDK command-line tools aren't properly installed or configured.
Problem Overview
The error message appears as:
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.
This occurs because Flutter's development tools require the Android SDK command-line utilities to function properly, but they're either missing or not properly detected.
Solution 1: Install via Android Studio GUI (Recommended)
The most straightforward solution is to install the command-line tools through Android Studio's interface:
For Android Studio 2020.3 and Later
- Open Android Studio
- Go to Settings → Languages & Frameworks → Android SDK → SDK Tools tab
- Check Android SDK Command-line Tools (latest)
- Click Apply or OK to install
For Older Android Studio Versions
- Open Android Studio
- Navigate to File → Settings → Appearance & Behavior → System Settings → Android SDK → SDK Tools tab
- Select Android SDK Command-line Tools (latest)
- Click Apply
Alternative Access Methods
If you don't see the standard menu options:
- From the welcome screen: Click More Actions → SDK Manager
- From the menu bar: Tools → SDK Manager
Solution 2: Manual Installation via Command Line
If the GUI method doesn't work or you prefer command-line tools:
macOS/Linux
cd ~/Library/Android/sdk/tools/bin
./sdkmanager --install "cmdline-tools;latest"
Windows
cd %LOCALAPPDATA%\Android\Sdk\tools\bin
sdkmanager --install "cmdline-tools;latest"
Ubuntu/Linux with Custom Path
/home/your_username/Android/Sdk/tools/bin/sdkmanager --install "cmdline-tools;latest"
Java Version Compatibility
If you encounter Java errors when running sdkmanager
, ensure you have a compatible Java version installed. The command-line tools may require specific Java versions to function properly.
Solution 3: Configure Flutter SDK Path
If the tools are installed but Flutter can't find them, explicitly set the Android SDK path:
flutter config --android-sdk "PATH_TO_YOUR_SDK"
Common SDK Paths by OS
flutter config --android-sdk "/Users/$USER/Library/Android/sdk"
flutter config --android-sdk "C:\Users\YourUsername\AppData\Local\Android\Sdk"
flutter config --android-sdk "/home/your_username/Android/Sdk"
After setting the path, accept the Android licenses:
flutter doctor --android-licenses
Type "y" to accept all licenses when prompted.
Solution 4: Environment Variables Setup
For persistent configuration, set the ANDROID_SDK_ROOT
environment variable:
Windows
- Open System Properties → Environment Variables
- Create a new system variable:
- Name:
ANDROID_SDK_ROOT
- Value: Path to your SDK (e.g.,
C:\Users\YourUsername\AppData\Local\Android\Sdk
)
- Name:
macOS/Linux
Add to your shell profile (.bashrc
, .zshrc
, or .profile
):
export ANDROID_SDK_ROOT="$HOME/Library/Android/sdk"
export PATH="$PATH:$ANDROID_SDK_ROOT/platform-tools:$ANDROID_SDK_ROOT/tools/bin"
Verification and Troubleshooting
After applying any solution, verify the fix by running:
flutter doctor
If the issue persists:
- Ensure you've restarted your terminal/command prompt after making changes
- Confirm the SDK path is correct with
flutter config --android-sdk
- Check that the command-line tools are actually installed in the SDK directory
- Try running
flutter doctor -v
for more detailed information
Complete Setup Script
For Linux users looking for a comprehensive setup solution, there's an automated installation script that handles SDK setup, Flutter installation, and path configuration.
Conclusion
The "cmdline-tools component is missing" error is a common but easily solvable issue in Flutter development. The recommended approach is to install the tools through Android Studio's SDK Manager, but command-line installation and path configuration are effective alternatives. Once resolved, you'll have a properly configured Android development environment for Flutter projects.