Mac配置Flutter环境

1.下载flutter

推荐去官网下载,速度并不慢,网址:
https://flutter.io/setup-macos/

2.配置环境变量

先把刚才下载的flutter_macos_vxxx.zip解压缩,笔者选择使用的目录是根目录下的APP文件夹。这个路径要用到。


Flutter版本.png

文件位置.png

配置环境变量,这里笔者使用命令行:

vim ~/.bash_profile

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

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

增加一行:

export PATH=/Users/abc/APP/flutter/bin:$PATH

保存一下,注意如果这个文件不存在,那么就新建一个。保存完毕之后运行命令:

source ~/.bash_profile

这个时候应该能运行flutter命令了,我们运行命令行:

flutter -h

3.检查环境

运行命令行:

flutter doctor
屏幕快照 2019-07-19 上午11.03.48.png

按照检测结果的说明,如果有[!] ✗ 标志,表示本行检测不通过,需要做一些设置或者安装一些软件。

1.下载并安装 Android Studio from: https://developer.android.com/studio/index.html

在配置文件里,配置Android SDK的路径

export ANDROID_HOME="/Users/abc/Library/Android/sdk"
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools

2.再下载添加插件:

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

1.打开android studio, 打开plugin


屏幕快照 2019-07-19 上午11.16.05.png

2.输入flutter搜索,install


屏幕快照 2019-07-19 上午11.16.11.png

3.配置android,一路点y即可。

flutter doctor --android-licenses

再次运行

flutter doctor
屏幕快照 2019-07-19 上午11.19.49.png
$ brew update
-bash: brew: command not found

安装brew

电脑没有安装过brew,那就进行安装。
尝试1:去官网https://brew.sh/下载,但是在终端中执行命令行,老是报错。意思大致是连不上'raw.githubusercontent.com'这个域名的服务器。

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
curl: (51) SSL: no alternative certificate subject name matches target host name 'raw.githubusercontent.com'

尝试2:那就换一种方式,使用安装文件进行安装
1.先把https://raw.githubusercontent.com/Homebrew/install/master/install文件下载下来(使用浏览器打开,另存为也可以),把文件命名为install.txt

rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
ruby  install.txt文件的绝对路径

第一行的rm命令,是为了防止之前你安装Homebrew失败而残留的文件,导致这次安装失败。
ruby install.txt执行之后,安装命令行提示安装,应该会安装成功。
安装成功后,执行以下命令检测:

$ brew doctor
Your system is ready to brew.

brew就安装成功了!

再次运行

flutter doctor

按照提示去运行命令行:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.7.8+hotfix.3, on Mac OS X 10.14.5 18F132, locale zh-Hans-CN)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 10.2.1)
[✗] iOS tools - develop for iOS devices
    ✗ 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
    ! Brew can be used to install tools for iOS device development.
      Download brew at https://brew.sh/.
[✓] Android Studio (version 3.4)
[!] Connected device
    ! No devices available

! Doctor found issues in 2 categories.

在运行flutter doctor,成功了

屏幕快照 2019-07-19 上午11.38.21.png

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容