Flutter基于Mac的环境配置

1、下载Flutter SDK

git clone https://github.com/flutter/flutter.git

2、配置Flutter镜像+Flutter环境变量

( 先创建.bash_profile文件,再将Flutter镜像+Flutter环境变量添加到bash_profile文件中)

  2.1 配置Flutter镜像

    2.1.1 进入当前用户的home目录:
cd ~/

   2.1.2 创建.bash_profile文件:
touch .bash_profile

   2.1.3 打开.bash_profile并编辑:
open .bash_profile ( 或者用:open $HOME/.bash_profile)

(以下三个镜像三选一,我一开始用的清华的,报错:curl: (60) SSL certificate problem: certificate has expired,后面换成官方提供的就👌了)

# 官方提供的国内镜像

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

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

# 上海交通大学提供的国内镜像

export PUB_HOSTED_URL=https://dart-pub.mirrors.sjtug.sjtu.edu.cn/

export FLUTTER_STORAGE_BASE_URL=https://mirrors.sjtug.sjtu.edu.cn/

#清华提供的国内镜像

export FLUTTER_STORAGE_BASE_URL=https://mirrors.tuna.tsinghua.edu.cn/flutter
export PUB_HOSTED_URL=https://mirrors.tuna.tsinghua.edu.cn/dart-pub

 2.2 配置Flutter环境变量,将环境变量添加至末尾。

#Flutter环境变量
export PATH="$PATH:/Users/liuguimei/Documents/flutterSDK/bin"

//我把下载的flutter文件放在了电脑的文稿里,而且用flutterSDK代替了下载的flutter这个外层文件名

 2.3 如终端安装了zsh插件,则按上面步骤添加环境变量至 ~/.zshrc

3、 刷新环境变量

source ~/.bash_profile

source ~/.zshrc(如安装zsh插件)

4、运行 flutter doctor

5、开发工具

   5.1. Xcode + Android Studio

   5.2. Visual Studio Code

 

《Flutter实战》电子书https://book.flutterchina.club/chapter1/mobile_development_intro.html#_1-1-1-%E5%8E%9F%E7%94%9F%E5%BC%80%E5%8F%91%E4%B8%8E%E8%B7%A8%E5%B9%B3%E5%8F%B0%E6%8A%80%E6%9C%AF

 

 

遇到的问题

问题一:cmdline-tools component is missing

解决办法:

1、打开Android Studio 偏好设置

 

 

2、操作如图示,就解决了。

 

 

 

问题二:Android toolchain - develop for Android devices (Android SDK version 31.0.0)

    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor

      --android-licenses

解决办法:

命令行跑 flutter doctor --android-licenses,

Review licenses that have not been accepted (y/N)? y 一路输入y,就解决了。

 

解决问题后跑flutter doctor,就可以看到安装的flutter的最新情况。

 

posted @ 2021-11-09 18:51  milaliu99  Views(431)  Comments(0)    收藏  举报