您好,欢迎来到花图问答。
搜索
您的当前位置:首页Flutter环境搭建(MAC)

Flutter环境搭建(MAC)

来源:花图问答

1 配置环境变量

由于在国内访问Flutter有时可能会受到限制,Flutter官方为中国开发者搭建了临时镜像,大家可以将如下环境变量加入到用户环境变量中:

export 
export 

2 获取Flutter SDK

首先确定你想把SDK安装到哪个目录,在该目录下创建development目录,名字可以随便取。但是为了跟各方面统一,建议使用名字development

test:~ 用户名$ pwd
/Users/[用户名]
test:~ [用户名]$ mkdir development

获取Flutter SDK方法一:

把下载的安装包放到该目录中,然后使用下边命令解压

unzip ~/Downloads/flutter_macos_v0.5.1-beta.zip

获取Flutter SDK方法二:

使用git操作

git clone 

3 添加flutter命令相关工具到path中:

export PATH=`pwd`/flutter/bin:$PATH

注意:此代码只能暂时针对当前命令行窗口设置PATH环境变量,所以暂时不要关闭当前命令行窗口

添加永久环境变量

  • 1 确定您Flutter SDK的目录,您将在步骤4中用到。
  • 2 打开(或创建) $HOME/.bash_profile. 文件路径和文件名可能在您的机器上不同.
  • 3 添加以下行并更改。
export  
export  
export PATH=/Users/[你的用户名,注意修改]/development/flutter/bin:$PATH
  • 4 运行命令 source $HOME/.bash_profile 刷新当前终端窗口
  • 5 随便再打开一个命令行窗口运行flutter命令检查,环境变量是否为全局永久的.有输出说明生效

例如:

 flutter -h

4 运行 flutter doctor检查依赖环境

flutter doctor

第一次运行一个flutter命令(如flutter doctor)时,它会下载它自己的依赖项并自行编译。以后再运行就会快得多。

该命令检查您的环境并在终端窗口中显示报告。Dart SDK已经在捆绑在Flutter里了,没有必要单独安装Dart。 仔细检查命令行输出以获取可能需要安装的其他软件或进一步需要执行的任务(以粗体显示)

例如:

gcl:~ [用户名]$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, v1.1.1-pre.2, on Mac OS X 10.13.4 17E199, locale
    zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    ✗ Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
    ✗ Verify that all connected devices have been paired with this computer in
      Xcode.
      If all devices have been paired, libimobiledevice and ideviceinstaller may
      require updating.
      To update with Brew, run:
        brew update
        brew uninstall --ignore-dependencies libimobiledevice
        brew uninstall --ignore-dependencies usbmuxd
        brew install --HEAD usbmuxd
        brew unlink usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ! CocoaPods out of date (1.5.0 is recommended).
        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 upgrade:
        brew upgrade cocoapods
        pod setup
[✓] Android Studio (version 3.2)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.30.0)
[✓] Connected device (1 available)

! Doctor found issues in 2 categories.

5 安装调试命令

2 打开终端并运行这些命令来安装用于将Flutter应用安装到iOS设备的工具

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

6 安装Flutter的编辑器

目前Flutter支持的编辑器分别为Android Studio、IntelliJ或VS Code。
MAC下我还是选择VS Code。

6.1 Visual Studio Code (VS Code) 安装
  • , 安装1.20.1或更高版本.
6.2 安装Flutter插件

1 启动 VS Code
2 调用 View>Command Palette…
3 输入 ‘install’, 然后选择 Extensions: Install Extension action
4 在搜索框输入 flutter , 在搜索结果列表中选择 ‘Flutter’, 然后点击 Install
5 选择 ‘OK’ 重新启动 VS Code

Copyright © 2019- huatuowenda.com 版权所有 湘ICP备2023022495号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务