Flutter 環(huán)境變量配置編輯.bash_profile
文件
一伯铣、編輯.bash_profile
文件
啟動iTerm
或者 Terminal
終端工具,終端命令進入自己用戶名下虎眨,查看是否存在隱藏文件bash_profile
,
? ~ cd ~/
? ~ ls -a
如果沒有則創(chuàng)建一個隱藏文件.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環(huán)境變量
export PATH=/Users/cosmo/Documents/flutter/bin:$PATH
#Android 環(huán)境變量
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 構(gòu)建工具路徑
#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 環(huán)境變量ANDROID_HOM
替換自己Android SDK
的sdk存放路徑剿吻,可去資源庫下查看我的Android SDK
的sdk存放路徑/Users/cosmo/Library/Android/sdk
(2)Android tools
路徑可在資源庫目錄下Android/sdk/build-tools/
查看實際的構(gòu)建版本文件名做相應(yīng)修改比如填寫30.0.3
28.0.3
(3)由于在國內(nèi)訪問Flutter可能會受到限制,F(xiàn)lutter官方為中國開發(fā)者搭建了臨時鏡像串纺,可以將
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
環(huán)境變量加入到用戶環(huán)境變量中丽旅,此鏡像為臨時鏡像,并不能保證一直可用纺棺,大家可以從 Using Flutter in China 上獲得有關(guān)鏡像服務(wù)器的最新動態(tài)榄笙。
二、驗證.bash_profile
文件
.bash_profile
編輯結(jié)束后保存祷蝌,iTerm
或者 Terminal
終端工具輸入source .bash_profile
命令可更新剛配置的環(huán)境變量即時生效
? ~ 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
已經(jīng)安裝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
續(xù)
1.更新flutter最新穩(wěn)定版本剑令,如果出現(xiàn)
? ~ 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
需要有效網(wǎng)絡(luò),然后再次運行即可