Flutter 「cmdline-tools component is missing」の対処法

Flutter 「cmdline-tools component is missing」の対処法

「Flutter doctor」実行に、「cmdline-tools component is missing」が発生した場合の対処法を記述してます。

環境

  • OS  windows11 pro 64bit
  • Flutter 3.3.1

エラー全文

以下のコマンドを、実行時に発生。

> flutter doctor

[√] Flutter (Channel stable, 3.3.1, on Microsoft Windows [Version 10.0.22000.978], locale ja-JP)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    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.
    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
[!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.6)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop
      development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Android Studio (version 2021.2)
[√] VS Code (version 1.70.1)
[√] Connected device (3 available)
[√] HTTP Host Availability

原因

「cmdline-tools」がインストールされていないため

対処法

「Android Studio」から「ファイル」>「設定」より

「Android SDK」のタブ「SDK Tools」を選択して「Android SDK Command-line Tools」をチェックして適応をクリックします。

「OK」ボタンをクリックするとインストールが開始されます。

これでエラーは改善されます。

> flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.1, on Microsoft Windows [Version 10.0.22000.978], locale ja-JP)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[√] Chrome - develop for the web
[!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.6)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop
      development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Android Studio (version 2021.2)
[√] VS Code (version 1.70.1)
[√] Connected device (3 available)
[√] HTTP Host Availability

! Doctor found issues in 2 categories.