目標

Flutter を macOS に構築する
基本的には https://flutter.io/setup-macos/ を参考に

システム要件

  • OS: macOS (64-bit)
  • ストレージ: 700 MB (IDE/tools除く)
  • 依存関係のあるツール: bash, mkdir, rm, git, curl, unzip, which

構築手順

1. Flutter SDK をダウンロード

方法は2とおり

1-1. zip

https://flutter.io/sdk-archive/#macos からSDKをダウンロード
今回は flutter_macos_v0.3.2-beta.zip を使います

$ cd ~/development
$ unzip ~/Downloads/flutter_macos_v0.3.2-beta.zip
$ ./flutter/bin/flutter --version
Flutter 0.3.2 • channel beta • https://github.com/flutter/flutter.git
Framework • revision 44b7e7d3f4 (4 weeks ago) • 2018-04-20 01:02:44 -0700
Engine • revision 09d05a3891
Tools • Dart 2.0.0-dev.48.0.flutter-fe606f890b

1-2. git clone

$ git clone -b master https://github.com/flutter/flutter.git

$ ./flutter/bin/flutter --version
 :
Flutter 0.4.5-pre.21 • channel master • https://github.com/flutter/flutter.git
Framework • revision f38743593d (2 hours ago) • 2018-05-15 19:37:21 -0700
Engine • revision 06afdfe54e
Tools • Dart 2.0.0-dev.54.0.flutter-46ab040e58

2. Flutter の依存関係を確認

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
 :

出てきた内容ごとに対応していく


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

ライセンスの問題だけだったのでそのまま実行

$ flutter doctor --android-licenses
 :
Accept? (y/N): y
All SDK package licenses accepted

[!] iOS toolchain - develop for iOS devices (Xcode 9.3.1)
    ✗ libimobiledevice and ideviceinstaller are not installed. To install, run:
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install:
        brew install ios-deploy
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
        For more info, see https://flutter.io/platform-plugins
      To install:
        brew install cocoapods
        pod setup
 :

上記そのまま対応する

$ brew install --HEAD libimobiledevice
$ brew install ideviceinstaller
$ brew install ios-deploy
$ brew install cocoapods
$ pod setup

もう一度 $ flutter doctor をしても次のエラーでたら

[!] iOS toolchain - develop for iOS devices (Xcode 9.3.1)
    ✗ Missing Xcode dependency: Python module "six".
      Install via 'pip install six' or 'sudo easy_install six'.

まずは

$ pip install six
Requirement already satisfied: six in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (1.4.1)
matplotlib 1.3.1 requires nose, which is not installed.
matplotlib 1.3.1 requires tornado, which is not installed.

となったら

$ brew reinstall python@2
 :
$ pip install six
Collecting six
  Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl
Installing collected packages: six
Successfully installed six-1.11.0

で、OK


[✓] Android Studio (version 3.1)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.

Android Studio から Preference... > Plugins > Browse repositories... で Flutter と Dart をインストール


[!] Connected devices
    ! No devices available

 エミュレータかデバイスを接続するとOKなのでこれはこのまま


全部成功するとこんな感じになる

$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v0.3.2, on Mac OS X 10.13.3 17D47, locale ja-JP)
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 9.3.1)
[✓] Android Studio (version 3.1)
[✓] VS Code (version 1.23.1)
[!] Connected devices
    ! No devices available

! Doctor found issues in 1 category.

$PATH の設定

.bash_profile に $PATH を追加する

$ cat .bash_profile
export PATH=`pwd`/development/flutter/bin:$PATH

動作チェック

AndroidエミュレータとiPhoneシミュレータを起動

$ ./Library/Android/sdk/tools/emulator -list-avds
Nexus_5X_API_26 // なかったらAVDでエミュレータを作成しておく

$ ./Library/Android/sdk/tools/emulator @Nexus_5X_API_26
$ open -a Simulator.app

Flutterアプリケーションの作成

$ flutter create myapp
Creating project myapp...
 :
All done! In order to run your application, type:

  $ cd myapp
  $ flutter run

Your main program file is lib/main.dart in the myapp directory.

アプリケーションの実行

$ flutter run -d all

スクリーンショット 2018-05-16 14.32.27.png

done.

Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.