Flutter环境搭建

1.下载Flutter

推荐去官网下载,可以下载最新的SDK,网址:
https://flutter.io/setup-macos/
下载后解压到你想放的目录。

2.配置环境变量

2.1、用以下命令打开环境变量配置文件:

open -e ~/.bash_profile

加入:

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export FLUTTER_GIT_HOME=/Users/didi/Documents/code/flutter2.5.0/flutter/bin
export PATH=${FLUTTER_GIT_HOME}:${PATH}

其中:FLUTTER_GIT_HOME 的 /Users/didi/Documents/code/flutter2.5.0/flutter 是我本地的Flutter解压后的路径。

2.2、测试是否配置成功:

flutter doctor

2.3、碰到的异常:

  1. /Users/didi/Documents/code/flutter/bin/internal/shared.sh: line 228: /Users/didi/Documents/code/flutter/bin/cache/dart-sdk/bin/dart: No such file or directory
    方案:下载的Flutter包缺少dart.exec,重新下载Flutter包;
    重新运行flutter doctor;

  2. cmdline-tools component is missing,如图:

    image.png

方案:打开Android Studio--SDK Manager--SDK Tools:

image.png

重新运行flutter doctor;

  1. Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses :
[!] 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

然后一路按y即可。

你可能感兴趣的:(Flutter环境搭建)