🤔
【Flutter】M1 Macのflutter doctorコマンド実行時のエラー解決法
はじめに
公式ドキュメントを参考にM1 MacでFlutterの開発環境を構築した後、環境に問題がないかチェックするflutter doctorコマンドを実行したところ、エラーが発生したので解決方法を記します。
実行環境
- PC: MacBook Pro
- チップ: Apple M1
- OS: macOS 13.4.1 (c)
- Xcode: 14.3.1
- Android Studio: version 2022.2
発生したエラー
✗マークの付いている箇所がエラーです。これらを1つずつ解決していきます。
Terminal
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.0, on macOS 13.4.1 22F770820d darwin-arm64,
locale ja-JP)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
✗ 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.3.1)
✗ Xcode end user license agreement not signed; open Xcode or run the command
'sudo xcodebuild -license'.
✗ Xcode requires additional components to be installed in order to run.
Launch Xcode and install additional required components when prompted or
run:
sudo xcodebuild -runFirstLaunch
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin
code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install see
https://guides.cocoapods.org/using/getting-started.html#installation for
instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.78.1)
Error executing simctl: 69
You have not agreed to the Xcode license agreements, please run 'sudo xcodebuild
-license' from within a Terminal window to review and agree to the Xcode license
agreements.
[✓] Connected device (2 available)
[✓] Network resources
解決方法
エラー1: cmdline-tools component is missing
✗ 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 Studioにcmdline-tools componentが存在しないというエラーなので、Android Studioを起動してCommand-line Toolsをインストールします。
インストール手順はこちらの記事を参考にしました↓
エラー2: Android license status unknown.
✗ 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.
メッセージの指示通り、flutter doctor --android-licensesコマンドを実行します。
ライセンスが表示されて、何度かAccept?(y/N)と聞かれるのでyを入力して同意します。
エラー3: Xcode end user license agreement not signed
✗ Xcode end user license agreement not signed; open Xcode or run the command
'sudo xcodebuild -license'.
メッセージの指示通り、sudo xcodebuild -licenseコマンドを実行します。
Xcodeのライセンスがターミナル上に表示されるので、指示通りにキーを入力してライセンスに同意します。
エラー4: Xcode requires additional components to be installed in order to run.
✗ Xcode requires additional components to be installed in order to run.
Launch Xcode and install additional required components when prompted or
run:
sudo xcodebuild -runFirstLaunch
Xcodeの追加コンポーネントが必要なので、インストールするためにsudo xcodebuild -runFirstLaunchコマンドを実行します。
エラー5: CocoaPods not installed.
✗ CocoaPods not installed.
CocoaPods is used to retrieve the iOS and macOS platform side's plugin
code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To install see
https://guides.cocoapods.org/using/getting-started.html#installation for
instructions.
メッセージに記されたサイトを参考に、CocoaPodsをインストールしました。
Terminal
$ sudo gem install cocoapods
再確認
エラー解決後にflutter doctorコマンドを再実行します。
Terminal
$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.0, on macOS 13.4.1 22F770820d darwin-arm64,
locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.78.1)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
すべてチェックマークがついていれば完了です!
おわりに
M1 Macのflutter doctorコマンド実行時のエラーを解決する方法を紹介しました。
誤り等ありましたらご指摘のほどよろしくお願いします。
Discussion