Flutterインストール📝 to Mac
自分のMacに以下サイトを参考にFlutterをインストールしたときの備忘録📝
環境
インストール
Get the Flutter SDK
Intel用のFlutter SDKファイル(zip)をダウンロードし解凍
解凍したファイルはホームディレクトリ配下に以下のように配置
$ cd $ cd Documents $ mkdir development $ cd development $ pwd /Users/chino/Documents/development # 解凍したファイルを移動 $ mv ~/Downloads/flutter ./ $ ls -la total 0 drwxr-xr-x 3 chino staff 96 7 24 10:49 . drwx------@ 58 chino staff 1856 7 24 10:49 .. drwxr-xr-x@ 27 chino staff 864 7 14 05:40 flutter
Flutterのパスを設定
$ vi ~/.zshrc # 以下を追記し保存 --- # flutter export FLUTTER_HOME="$HOME/Documents/development/flutter" export PATH="$PATH:$FLUTTER_HOME/bin" ---
Run Flutter Doctor
flutterの doctor
というコマンドでFlutterに必要な開発環境が準備できているか確認できるので実行💻
$ flutter doctor ╔════════════════════════════════════════════════════════════════════════════╗ ║ Welcome to Flutter! - https://flutter.dev ║ ║ ║ ║ The Flutter tool uses Google Analytics to anonymously report feature usage ║ ║ statistics and basic crash reports. This data is used to help improve ║ ║ Flutter tools over time. ║ ║ ║ ║ Flutter tool analytics are not sent on the very first run. To disable ║ ║ reporting, type 'flutter config --no-analytics'. To display the current ║ ║ setting, type 'flutter config'. If you opt out of analytics, an opt-out ║ ║ event will be sent, and then no further information will be sent by the ║ ║ Flutter tool. ║ ║ ║ ║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║ ║ Note: The Google Privacy Policy describes how data is handled in this ║ ║ service. ║ ║ ║ ║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║ ║ crash reports to Google. ║ ║ ║ ║ Read about data we send with crash reports: ║ ║ https://flutter.dev/docs/reference/crash-reporting ║ ║ ║ ║ See Google's privacy policy: ║ ║ https://policies.google.com/privacy ║ ╚════════════════════════════════════════════════════════════════════════════╝ Running "flutter pub get" in flutter_tools... 10.3s Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-x64, locale ja-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 13.4.1) ✗ 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 (not installed) [✓] VS Code (version 1.69.1) [✓] Connected device (2 available) [✓] HTTP Host Availability ! Doctor found issues in 3 categories.
以下がまだ準備できていなかった
- Android toolchain - develop for Android devices
- Xcode - develop for iOS and macOS (Xcode 13.4.1)
- →CocoaPodsがインストールされていない⚠
CocoaPodsのインストール
To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
ということなのでCocoaPods Guides - Getting Startedを参照しインストール👀
$ sudo gem install cocoapods
パスを設定
$ vi ~/.zshrc # 以下を追記し保存 --- export GEM_HOME=$HOME/.gem export PATH=$GEM_HOME/bin:$PATH ---
もう一度、 doctor
を実行!
$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-x64, locale ja-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 13.4.1) [✓] Chrome - develop for the web [!] Android Studio (not installed) [✓] VS Code (version 1.69.1) [✓] Connected device (2 available) [✓] HTTP Host Availability ! Doctor found issues in 2 categories.
Xcodeについては準備完了🙆
Android関連のインストール
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
ということなのでmacOS install | Flutterを参照しセットアップ!
まずはAndroid Studioをインストール
インストール後、Android Studioを起動し初期セットアップも完了
再び doctor
を実行!
flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-x64, locale ja-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 13.4.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] VS Code (version 1.69.1) [✓] Connected device (2 available) [✓] HTTP Host Availability ! Doctor found issues in 1 category.
✗ cmdline-tools component is missing
macOS install | FlutterのページでAndroid Studioの初期セットアップ時にインストールされると記載があったがなぜかインストールされず。。。一応、 sdkmanager
を実行してみたが command not found
になってしまった・・・
このため、こちらのDownload Android Studio & App Tools - Android Developersからzipファイルをダウンロードできるようなのでダウンロード、解凍してSDK配下に配置
# SDK配下に移動 $ cd /Users/chinoyuuji/Library/Android/sdk # ダウンロードして解凍したcommand-toolsをsdk配下に配置 $ sudo mv ~/Downloads/cmdline-tools ./
SDKの場所はAndroid Studioを起動し確認しました
sdkmanagerのパスを設定
$ vi ~/.zshrc # 以下を追記し保存 --- # Android export ANDROID_USER_HOME="/Users/chinoyuuji/Library/Android" export ANDROID_HOME="$ANDROID_USER_HOME/sdk" export ANDROID_CMDLINE_TOOLS="$ANDROID_HOME/cmdline-tools" export PATH="$PATH:$ANDROID_CMDLINE_TOOLS/bin" ---
sdkmanagerの最新をインストール
$ sdkmanager --install "cmdline-tools;latest" The operation couldn’t be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java.
JAVAがインストールしていなかったので、http://www.java.comからjavaをインストールしてから再度、コマンドを実行
$ 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/
SDKのパスを指定が必要だったので指定して再実行!
$ sdkmanager --install "cmdline-tools;latest" --sdk_root=/Users/chinoyuuji/Library/Android/sdk [=======================================] 100% Unzipping... cmdline-tools/lib/RE
できたみたいなので、 doctor
で出力されていたもうひとつのコマンドを実行(すべて「y」で承諾)
$ flutter doctor --android-licenses ・・・ All SDK package licenses accepted
再び、 doctor
を実行👀
$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-x64, locale ja-JP) Checking Android licenses is taking an unexpectedly long time...[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.4.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2021.2) [✓] VS Code (version 1.69.1) [✓] Connected device (2 available) [✓] HTTP Host Availability • No issues found!
No issues found!
になり準備完了🙌