天天看点

flutter 环境配置 for Mac Os

flutter 中文官网

https://flutterchina.club/setup-macos/

按这个可以装完环境。

对于 iOS 相关部分 xcode工具和vscode 工具的安装不作说明。

1.下载flutter SDK https://flutter.dev/docs/development/tools/sdk/archive?tab=macos#macos

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

下载到本机某个文件夹,具体自行定义啦。

2.设置好flutter 的国内镜像环境变量。

vim .bash_profile

添加

#国内用户需要设置

export PUB_HOSTED_URL=https://pub.flutter-io.cn

export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn

export PATH=/Users/a/Documents/flutter/sdk/flutter/bin:$PATH

基中/Users/a/Documents/flutter/sdk/flutter/bin这个就是你第一步git 克隆下来的具体位置路径。

3.执行 flutter doctor            //这个命令取的真好,有意思哈。医生。作用就像医生一样,执行后帮你检测当前的环境是否OK。

我第一次执行的日志:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.3.11-pre.39, on Mac OS X 10.14 18A391, locale
    zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
    ✗ 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
[!] Android Studio (version 3.2)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Ultimate Edition (version 2018.1.5)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[!] VS Code (version 1.32.0)
    ✗ Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[!] Connected device
    ! No devices available

! Doctor found issues in 6 categories.
           

 可以看到 iOS和vscode都还不ok.

 3.装ios 连接。

    按医生叮嘱的来做。

        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

4.对vscode安装flutter插件。记得安装完成后需要重起。

vscode安装插件这个应该会吧。

安装完成后在命令行面板(command palette) shift+command+p 中输入 flutter

flutter 环境配置 for Mac Os

接着要求输出项目名称:按教程来先。myapp

flutter 环境配置 for Mac Os

生成myapp的目录结构如下:

flutter 环境配置 for Mac Os

然后打开debug 下进行配置

flutter 环境配置 for Mac Os

然后点绿色run.如果ios的模拟器打开了就会跑起来了。

flutter 环境配置 for Mac Os

真机配置:

到我们myapp的目录:

flutter 环境配置 for Mac Os

用xcode打开workspace文件。然后配置相关证书就OK了。配置后,插上真机就可以直接跑了。这个配置对于懂ios开发工具的就下当简单,非ios开发的话,可能会被证书搞蒙。

flutter 环境配置 for Mac Os

保存回到vscode中,插上真机运行。

flutter 环境配置 for Mac Os
flutter 环境配置 for Mac Os

真机的运行效果。好了。今天就到这。