1、下载Flutter Sdk
https://flutter.cn/docs/get-started/install/macos#get-sdk
下载完成后,新建一个你期望存放sdk的目录,然后将下载的压缩包直接解压得到fluter文件夹;
2、配置环境变量
打开或者创建 shell 的 rc (该文件时一般都会选择在当前用户目录下,即Mac下的.bash_profile 文件的路径是 /Users/YourMacUserName/.bash_profile (如果该文件已经创建过的话))文件,比如,在 Linux 和 macOS Mojave 或 Mojave 之前的系统里,是默认使用 Bash 的,所以需要修改 $HOME/.bashrc 文件。 macOS Catalina 操作系统默认使用 Z Shell,所以需要修改 $HOME/.zshrc 文件。请知晓,如果你使用不同的 shell,文件目录或文件名可能会有所不同。(我这里用的是zshrc,如果使用zshrc步骤跟下面的一样,就把文件名换下就可以了)
1、创建 .bash_profile
(1) 启动终端(可以在任意目录下打开) (2) 进入当前用户的home目录(默认就是): cd ~ 或 cd /Users/YourMacUserName (3)输入touch .bash_profile
2、查看 、编辑 .bash_profile 文件
(1)终端输入 open -e .bash_profile 如果只是查看,直接使用open .bash_profile;如果电脑上面存在这个文件,可以直接输入下面地址打开 open ~/.bash_profile (2)编辑:在文件中配置
export PATH=/Users/username/development/flutter/bin:$PATH
(3)关闭即可保存修改 (4)使用source ~/.bash_profile来刷新一下
3、验证 flutter 命令是否可用
which flutter flutter doctor
[✓] Flutter (Channel stable, 3.10.4, on macOS 12.3 21E230 darwin-x64, locale
zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version
33.0.0-rc2)
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.78.2)
[✓] Connected device (2 available)
[✓] Network resources
• No issues found!
这样就算配好了! 有时候不会这么顺利,可能会遇到 1、Flutter 环境配置提示Android Studio cmdline-tools component is missing 打开Android Studio的设置->Android Sdk->Sdk Tools->cmdline-tools前面的多选框勾上,点apply 2、Some Android licenses not accepted. 输入命令flutter doctor --android-licenses,一路输入y 3、network resources https://www.jianshu.com/p/b69231defaaf
文章链接
发表评论