Flutter 环境变量配置编辑.bash_profile
文件
一、编辑.bash_profile
文件
启动iTerm
或者 Terminal
终端工具,终端命令进入自己用户名下,查看是否存在隐藏文件bash_profile
,
➜ ~ cd ~/
➜ ~ ls -a
如果没有则创建一个隐藏文件.bash_profile
,
➜ ~ touch .bash_profile
如果存在,若只是查看输入open ~/.bash_profile
打开,若是编辑open -e ~/.bash_profile
打开
➜ ~ open ~/.bash_profile
➜ ~ open -e ~/.bash_profile
编辑后
# HomeBrew
export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles
export PATH="/usr/local/bin:$PATH"
export PATH="/usr/local/sbin:$PATH"
# HomeBrew END
#Flutter镜像
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
#Flutter环境变量
export PATH=/Users/cosmo/Documents/flutter/bin:$PATH
#Android 环境变量
export ANDROID_HOME=/Users/cosmo/Library/Android/sdk
#Android 模拟器路径
export PATH=${PATH}:${ANDROID_HOME}/emulator
#Android tools 路径
export PATH=${PATH}:${ANDROID_HOME}/tools
#Android 平台工具路径
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
#Android 构建工具路径
#export PATH=${PATH}:${ANDROID_HOME}/build-tools/30.0.3
#Android NDK路径
#ANDROID_NDK_HOME=/Users/cosmo/Library/Android/ndk/android-ndk-r10e
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
注意:
(1)Android 环境变量ANDROID_HOM
替换自己Android SDK
的sdk存放路径,可去资源库下查看我的Android SDK
的sdk存放路径/Users/cosmo/Library/Android/sdk
(2)Android tools
路径可在资源库目录下Android/sdk/build-tools/
查看实际的构建版本文件名做相应修改比如填写30.0.3
28.0.3
(3)由于在国内访问Flutter可能会受到限制,Flutter官方为中国开发者搭建了临时镜像,可以将
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
环境变量加入到用户环境变量中,此镜像为临时镜像,并不能保证一直可用,大家可以从 Using Flutter in China 上获得有关镜像服务器的最新动态。
二、验证.bash_profile
文件
.bash_profile
编辑结束后保存,iTerm
或者 Terminal
终端工具输入source .bash_profile
命令可更新刚配置的环境变量即时生效
➜ ~ source .bash_profile
在终端Terminal
或者iTerm
输入flutter doctor
进行检查。
Last login: Fri Jan 29 16:37:30 on ttys010
➜ ~ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.5, on Mac OS X 10.15.7 19H2 darwin-x64, locale
zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.3)
[!] Android Studio (version 4.1)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.52.1)
[✓] Connected device (2 available)
! Doctor found issues in 1 category.
➜ ~
Android Studio
已经安装Flutter
和Dart
插件,项目正常运行flutter doctor
依然报
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
最新Android Studio
毛病多,略之。
即ok
续
1.更新flutter最新稳定版本,如果出现
➜ ~ flutter doctor
VersionCheckError: Command exited with code 128: git fetch
__flutter_version_check__ stable
Standard error: fatal: unable to access
'https://github.com/flutter/flutter.git/': LibreSSL SSL_connect:
SSL_ERROR_SYSCALL in connection to github.com:443
需要有效网络,然后再次运行即可