M1 ProのマシンでFlutter開発環境を準備する

11月にNew MBPを手に入れてFlutter開発環境を整えたものの、Kernel Panic発生により入院、初期化となりました😇

MBPが帰ってきたので再整備しようとしたところエラーが起きたのでメモ📝

Flutter

公式を参考にSDKを入手します。

https://docs.flutter.dev/get-started/install/macos

flutter doctor で確認

$ 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...                    1,952ms
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale en-JP)
[!] Android toolchain - develop for Android devices (Android SDK version 32.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 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.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[☠] IntelliJ IDEA Ultimate Edition (the doctor check crashed)
    ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at
      https://github.com/flutter/flutter/issues.
    ✗ FormatException: Unexpected extension byte (at offset 5)
[✓] VS Code (version 1.63.0)
[✓] Connected device (1 available)

! Doctor found issues in 3 categories.

何やらいろいろ出ています。

Android Studio & toolchain

こちらも普通に公式からDL. ARM版が用意されている。

android-studio-2020.3.1.26-mac_arm.dmg

Download Android Studio and SDK tools  |  Android Developers

f:id:suzusin:20211219120854p:plain

11月に試した時はRC版でないとSDKのDLがされなかった記憶がありますが、12月時点では大丈夫そうです。

f:id:suzusin:20211219121200p:plain
android-studio-welcome

Android toolchain

コマンドラインからインストールできるようですが、今回はポチポチ入れてみました。

More Actions から、 SDK Manager を選択。 Android SDK Command-line Tools にチェックを入れてインストールします。

f:id:suzusin:20211219121343p:plain
android-sdk

再度 flutter doctor を実行すると、 licenses not accepted の表示に変わりました。

[!] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses

ここは指示どおりに flutter doctor --android-licenses を実行。

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)

Xcodeは AppStore からインストールしていました。 残った cocoapodsCocoaPods Guides - Getting Started を参照せよとのこと。そして公式の指示どおりにインストール。

sudo gem install cocoapods

再度 flutter doctor を実行。ここまでで、この状態。

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale en-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[☠] IntelliJ IDEA Ultimate Edition (the doctor check crashed)
    ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at
      https://github.com/flutter/flutter/issues.
    ✗ FormatException: Unexpected extension byte (at offset 5)
[✓] VS Code (version 1.63.0)
[✓] Connected device (1 available)

IntelliJ IDEA

IntelliJは普段使いしているので、別途インストール済みでしたが、これが何やら怒られています。 既にIssueが上がっていました。まだ直っていない様子。

github.com

IntelliJ 2021.2 だと動くというコメントがありました。手元の IntelliJ は 2021.3 だったので、一時的にDowngradeすることにしました。

https://www.jetbrains.com/toolbox-app/ から Toolbox を手に入れると、過去のバージョンを簡単に入手できます。

f:id:suzusin:20211219122707p:plain

2021.2 をインストールして、再度 flutter doctor を実行。

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-arm, locale en-JP)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.3)
[✓] VS Code (version 1.63.0)
[✓] Connected device (1 available)

• No issues found!

無事、環境を復活させることができました。