こんにちは、CX事業本部 IoT事業部の若槻です。
FlutterでiOSアプリ開発をする際に開発環境の正常性確認のためにFlutter Doctorコマンドを実行することがあるのですが、私の環境ではその際にAndroid開発環境周り(「Android toolchain」および「Android Studio」)のIssueが常に出ています。
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.6 21G115 darwin-arm, locale en-JP)
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] VS Code (version 1.72.0)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 2 categories.
iOSアプリ開発のみをする上では別に問題は無いのですが、目の上のたんこぶ的な鬱陶しさがありますね。
そこで今回は、Flutter DoctorのAndroid周りのIssueを解消を試してみました。
やってみる
とりあえずAndroid Studioが未導入なので導入してみます。
インストーラーをダウンロード。
M1 MACなので[Mac with Apple chip]を選択。
ダウンロードしたらインストール。
Android Studioのアプリを起動できました。
ここで再度Flutter Doctorを実行してみると、Android Studioに関するエラーは解消しましたが、Android toolchainについては引き続きエラーとなっています。Android StudioをインストールしただけだとAndroid SDKは導入されないようです。
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.6 21G115 darwin-arm, locale en-JP)
[✗] Android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.72.0)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 1 category.
Android Studioのアプリに戻り、ウィザードを進めます。
ライセンスに同意するとコンポーネントのダウンロードが始まりました。
ダウンロード完了。
ここでFlutter Doctorを実行すると、引き続きAndroid toolchainのエラーが出ていますが、その内容が変わりました。
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.6 21G115 darwin-arm, locale en-JP)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.72.0)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 1 category.
まずcmdline-tools component is missing
というエラーの解消を試みます。path/to/sdkmanager --install "cmdline-tools;latest"
コマンドを実行してcmdline-tools
を導入するようにありますが、SDK ManagerはAndroid Studioのコンソールからも操作できるのでコンソールからcmdline-tools
を導入をしてみます。
Android Studioで適当にプロジェクトを作成し、[Tools > SDK Manager]を選択。
[Android SDK > SDK Tools]でAndroid SDK Command-line Tools (latest)
にチェックを入れ、[Appky]をクリック。
[OK]してインストールします。(結構ディスク容量を使うんですね)
完了しました。
Flutter Doctorを実行すると、cmdline-tools component is missing
のエラーは解消されました!
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.6 21G115 darwin-arm, locale en-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
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.72.0)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 1 category.
最後のSome Android licenses not accepted.
の解消を試みます。記載のコマンドを実行します。
$ flutter doctor --android-licenses
コマンドの実行中に何度かYes/Noを聞かれるので、Acceptします。
License Acceptが正常に完了した後にFlutter Doctorを実行すると、Issueがすべて解消されました!
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.6 21G115 darwin-arm, locale en-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.72.0)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
• No issues found!
参考
以上