Mac 下 Flutter 开发环境搭建

一、安装 Flutter SDK

  1. 下载 Flutter SDK 并解压。

  2. 移动到Home下,并设置环境变量。

1
2
3
4
mv flutter/ ~
vim ~/.bash_profile
export PATH="~/flutter/bin:$PATH"
source ~/.bash_profile

二、安装 Dart SDK

1
2
3
4
5
6
7
brew tap dart-lang/dart
brew install dart
brew info dart
# 可以得到 Dart SDK 的路径
==> Caveats
Please note the path to the Dart SDK:
  /usr/local/opt/dart/libexec

三、配置 Android 开发环境

  1. 下载 Android Studio 并安装。

  2. 打开Android Studio,挂上代理,确保Downloading Components顺利完成。

  1. 安装Flutter插件。
  1. 同意Android licenses
flutter doctor --android-licenses
  1. 根据需要安装JDK
1
2
3
4
5
# 安装最新版
brew cask install java
# 或者安装 JDK 8
brew tap caskroom/versions
brew cask install java8

四、配置 iOS 开发环境

  1. App Store 中下载Xcode并安装。

  2. 下载并安装 Command Line Tools (macOS 10.14) for Xcode 10.2

  3. flutter doctor出现以下提示。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[✗] iOS toolchain - develop for iOS devices
    ✗ 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
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with
      Brew, run:
        brew update
        brew install --HEAD usbmuxd
        brew link usbmuxd
        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
  1. 依次解决。
1
2
3
4
5
6
7
8
9
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
brew install ios-deploy
brew install cocoapods
pod setup

五、使用 IntelliJ IDEA 创建 Flutter 项目

  1. 安装Flutter插件。

  2. 创建一个 Flutter 项目。

  1. 设置 Dart SDK 的路径。
1
/flutter/bin/cache/dart-sdk

参考资料

  1. 入门: 在macOS上搭建Flutter开发环境
  2. mac 上配置flutter开发环境