1. 更新环境变量
安装Flutter SDK的时候,更新环境变量,将Flutter添加到PATH中,如果使用的终端是zsh
,终端启动时 ~/.bash_profile
将不会被加载。
配置好环境变量后,启动终端,运行source $HOME/.bash_profile
更新时,报如下错:
/Users/mariko/.zshrc:source:74: no such file or directory: ~/.bash_profile
运行echo $PATH
也看不到flutter/bin
。
解决办法就是修改 ~/.zshrc
,在其中添加:source /Users/mariko/.bash_profile
,注意需要要使用全路径。
2.flutter doctor 检查发现 Android license status unknow
运行 flutter doctor
发现报错 Android license status unknown.
~ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.6 19G2021, locale
zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
✗ Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit
https://flutter.dev/docs/get-started/install/macos#android-setup for
detailed instructions.
[✓] Xcode - develop for iOS and macOS (Xcode 11.6)
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.48.2)
[✓] Connected device (1 available)
! Doctor found issues in 1 category.
网上很多帖子需要更新 Android SDK,或者JDK版本过高需要降级等。
这里首先需要检查下Android Studio 中 是否已下载 Android SDK Command-line Tools
。
安装成功后flutter doctor
检查提示需要运行flutter doctor --android-licenses
,运行命令后,后续操作只需一直输入y
就可以了。最后运行查看问题没有了。
3.生成注释文档
将当前项目中的注释转化为文档时,使用dart 命令
dartdoc
若报错:
dartdoc failed: Top level package requires Flutter but FLUTTER_ROOT environment variable not set.
需单独配置 FLUTTER_ROOT
环境变量:
export FLUTTER_ROOT=你的 flutter 安装目录
最终Flutter环境变量配置如下:
# Pub 源(镜像)配置
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
# flutter 环境变量
export FLUTTER_ROOT=/opt/flutter
export FLUTTER=$FLUTTER_ROOT/bin
export PATH=$FLUTTER:$PATH
# dart 环境变量
export PATH=$FLUTTER/cache/dart-sdk/bin:$PATH
使命令重新加载生效
source ~/.bash_profile
或
source ~/.zshrc