まっさらな状態のMac MiniにFlutter環境を構築する


## 前提
- MacOS Big Sur
- Mac mini (2018)
- Flutterのバージョンをプロジェクトごとに管理するために、`fvm`を使用しています

## まっさらなMac MiniにFlutter環境を構築する

- homebrew install
  - [公式](https://brew.sh/index_ja)

```
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

- fvmをインストール

```
brew tap leoafarias/fvm
brew install fvm
```

- pass into .zshrc
    - zshを使用しているので環境設定

```
echo 'export PATH="$PATH":"$HOME/.pub-cache/bin"' >> ~/.zshrc
```

- Flutterパッケージをインストール

```
fvm flutter pub get
```

- Flutter doctor
    - 環境構築できているか診断する

```
fvm flutter doctor
```

- 結果

```
% fvm flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel unknown, 2.2.0, on macOS 11.3.1 20E241 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 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 (not installed)
[✓] Connected device (1 available)! Doctor found issues in 3 categories.
```



- Android Studioを公式からインストールする
  - https://developer.android.com/studio

- Xcodeをインストールする
  - AppStoreでインストールする

- cocoapods install
  - cocoapodsはswiftのパッケージマネージャー

```
sudo gem install cocoapods
```

- flutter doctor --android-licenses
  - 上のコマンドを実行してもエラーが出る

```
% flutter doctor --android-licenses
zsh: command not found: flutter
% fvm flutter doctor --android-licenses
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
        at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
        at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
        at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 5 more
```

- Android StudioでAndroid SDK toolsのパッケージ名が、Android-SDK command line toolsに変更

- 添付のようにAndroidStudioで設定する

![スクリーンショット 2021-06-15 15.03.36.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/267662/ed850377-fb15-d317-42f3-8ee65b40f71d.png)


- 再度、同意する


  - すべてyes

```
fvm flutter doctor --android-licenses
```


- 再度Flutter doctor
    - 環境構築できているか診断する

```
fvm flutter doctor
```

- すべてチェックがついているはず
- これで環境は構築できています

## あとはエディターにfvmの設定を行う必要がある ←後日書きます
- VSCode
- Android Studio