LoginSignup
2
1

More than 1 year has passed since last update.

Flutter SDKのダウンロードからflutter doctorコマンドによる環境のセットアップまで

Last updated at Posted at 2022-05-26

Apple SiliconのMacで行った。

flutterコマンドの確認

・ロゼッタのインストール

$ sudo softwareupdate --install-rosetta --agree-to-license

Get the Flutter SDKにあるApple Siliconのボタンをクリックし、3.0.1のSDK(現時点の最新)をzipとしてダウンロード。
・ホーム画面にflutterというフォルダを作り、その中でzipを解凍(別にflutterでなくてもよい)

$ cd
$ mkdir flutter
$ cd flutter
$ unzip ~/Downloads/flutter_macos_3.0.1-stable.zip

・パスを通す

$ export PATH="$PATH:[ホームディレクトリのPATH]/flutter/flutter/bin" 

・ターミナル起動時に毎回パスを通すため、ホーム画面にある.zshrcファイルにも以下を追加(Zsh以外ならそれ専用のファイルに追加。例えばBashなら.bath_profileもしくは.bashrc。使っているシェルの確認はecho $SHELLでわかる)

export PATH="$PATH:[ホームディレクトリのPATH]/flutter/flutter/bin" 

・ターミナルを再起動
・PATHを確認

$  echo $PATH
[ホームディレクトリのPATH]/flutter/flutter/bin

・flutterコマンドが使えるか確認

$ which flutter
[ホームディレクトリのPATH]/flutter/flutter/bin/flutter

・flutter doctorコマンドでセットアップ完了に必要な依存性の確認

$ flutter doctor

すると、Android toolchainとXcodeのセットアップについて不完全であることが示された。

Android toolchainのセットアップ

・flutter doctorコマンドの最初の出力

[❌] 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.

・Android Studioをインストールし、立ち上げ、ボタンをぽちぽち押していく
・再びflutter doctorコマンドを打つと出力内容が変化

$ flutter doctor
❌ 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.

提示されたリンクを参考にしながら作業を行なっていく。
・Android Studioで[File] > [Project Structure] > [SDK Location]でAndroid SDKの場所が以下であることを確認

/Users/[username]/Library/Android/sdk

・念の為、Android SDKにコマンドラインツールは含まれているか確認したが、cmdline-toolsというディレクトリはなかった

$ cd /Users/[username]/Library/Android/sdk
$ ls
cmdline-toolsのディレクトリは確認されず

・仕方ないので、ここからコマンドラインツールをダウンロード。
・zipを解凍し、cmdline-toolsディレクトリの中にあるsdkmanagerコマンドを実行

$ /Users/[username]/Downloads/cmdline-tools/bin/sdkmanager --install "cmdline-tools;latest"
Error: Could not determine SDK root.
Error: Either specify it explicitly with --sdk_root= or move this package into its expected location: <sdk>/cmdline-tools/latest/

・エラーが出た。Android SDKのパスを指定しないといけないらしい

$ /Users/[username]/Downloads/cmdline-tools/bin/sdkmanager --sdk_root=/Users/[username]/Library/Android/sdk  --install "cmdline-tools;latest"
成功

再びAndroid SDKの中身を見ると、cmdline-tools/latestディレクトリが作成されていることが確認できた。
・ライセンスをAcceptしていく

$ flutter doctor --android-licenses

・flutter commandでAndroid toolchainについては解決したことを確認

$ flutter doctor
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)

Xcodeのセットアップ

・flutter doctorコマンドの最初の出力

[❌] Xcode - develop for iOS and macOS
   ❌ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        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.

・Xcodeの「a full installation」とはなんのことか分からなかったが、とりあえずここでXcode13.4(現時点での最新)をダウンロードし、初回起動時にAdditional Toolsもダウンロードする。そのあとCommand Line Toolもダウンロードしておく
・指示通りに以下のコマンドを打つ

$ sudo xcode-select --switch [ダウンロードしたXcode.appがある場所]/Xcode.app/Contents/Developer
$ sudo xcodebuild -runFirstLaunch

・flutter doctorコマンドを打つと以下のような出力を確認(Android toolchainのものも含めた全文)

$ flutter doctor
2022-05-30 18:45:35.646 xcodebuild[12540:741500] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionSentinelHostApplications for extension Xcode.DebuggerFoundation.AppExtensionHosts.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
2022-05-30 18:45:35.647 xcodebuild[12540:741500] Requested but did not find extension point with identifier Xcode.IDEKit.ExtensionPointIdentifierToBundleIdentifier for extension Xcode.DebuggerFoundation.AppExtensionToBundleIdentifierMap.watchOS of plug-in com.apple.dt.IDEWatchSupportCore
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.1, on macOS 12.4 21F79 darwin-arm, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[!] Xcode - develop for iOS and macOS (Xcode 13.4)
   ❌ 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 2021.2)
[✓] VS Code (version 1.64.1)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

マシにはなったが最初のコメントが気になる(watchOS?)。が、一旦無視。
・CocoaPodsのインストール

$ sudo gem install cocoapods

・flutter doctorコマンドを打つと、全てクリアしたことを確認!

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.1, on macOS 12.4 21F79 darwin-arm, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.64.1)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

• No issues found!

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1