本文詳細介紹在mac下配置flutter環境的每個步驟,經過圖文的方式使得讀者快速理解和掌握flutter的環境搭建流程。python
macOS (64-bit) 硬盤空間: 700 MB (不包含android studio等編輯器工具). 命令行工具:bash, mkdir, rm, git, curl, unzip, which,brew須要保證上述命令在命令行下能使用,android
若是沒有安裝brew,那麼須要先安裝:參考:https://segmentfault.com/a/1190000013317511ios
推薦去官網下載,速度並不慢,網址:git
https://flutter.io/setup-macos/github
點擊連接:macos
更新後的連接地址:vim
https://storage.googleapis.com/flutter_infra/releases/beta/macos/flutter_macos_v0.4.4-beta.zipsegmentfault
先把剛纔下載的flutter_macos_v0.3.2-beta.zip解壓縮,筆者選擇使用的目錄是根目錄下的app文件夾api
配置環境變量,這裏筆者使用命令行:android-studio
vim ~/.bash_profile
複製代碼
增長一行:
export PATH=/app/flutter/bin:$PATH
複製代碼
保存一下,注意若是這個文件不存在,那麼就新建一個。保存完畢以後運行命令:
source ~/.bash_profile
複製代碼
這個時候應該能運行flutter命令了,咱們運行命令行:
flutter -h
複製代碼
這個時候應該能展現flutter的命令幫助:
運行命令行:
flutter doctor
複製代碼
按照檢測結果的說明,若是有[!] ✗ 標誌,表示本行檢測不經過,須要作一些設置或者安裝一些軟件。
若是android studio沒有安裝,那麼能夠先裝下,並使用android studio下載最新的android sdk。android studio下載地址:http://www.android-studio.org/
若是有安裝,那麼頗有可能看到:
[!] Android toolchain - develop for Android devices (Android SDK 27.0.3) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licens
須要運行
flutter doctor --android-licenses
複製代碼
這裏界面會要求輸入Y/N,一路輸入Y就好了。
✗ ideviceinstaller is not installed; this is used to discover connected iOS devices. To install, run: brew install --HEAD libimobiledevice brew install ideviceinstaller ✗ ios-deploy not installed. To install: brew install ios-deploy ✗ CocoaPods not installed. CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side. Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS. For more info, see https://flutter.io/platform-plugins To install: brew install cocoapods pod setup
運行命令:
brew install --HEAD libimobiledevice
brew install ideviceinstaller
brew install ios-deploy
brew install cocoapods
pod setup
複製代碼
這個步驟有點慢...
固然讀者看到的也許和筆者不太一致,請酌情處理。
這裏出現了個錯誤,按照說明,運行:
brew link --overwrite cocoapods
複製代碼
而後繼續運行:
pod setup
複製代碼
若是直接運行這個命令,會至關慢,那麼咱們曲線解決:
cd ~/.cocoapods/repos
git clone https://github.com/CocoaPods/Specs.git
複製代碼
若是仍是太慢,那麼去
連接:https://pan.baidu.com/s/1mQ1VvslwwccdoLRi-I0pNg 密碼:lax1
下一份,解壓縮到~/.cocoapods/repos/master目錄
[✓] Android Studio (version 3.0) ✗ Flutter plugin not installed; this adds Flutter specific functionality. ✗ Dart plugin not installed; this adds Dart specific functionality.
打開android studio, 打開plugin
輸入flutter搜索,點擊中間的 Search in repositories
點擊install,順利的話安裝完畢以後重啓android studio
再次運行
flutter doctor
複製代碼
注意這裏有個坑,若是按照指引來作,會一直卡在這裏。這裏要先重裝一下python,運行下面的命令:
brew reinstall python@2
pip install six
複製代碼
再次運行
flutter doctor
複製代碼
若是順利,能夠看到環境ok
若是在國內,你懂的,還須要設置一下pub源,否則就不能愉快的使用別人寫的庫。
運行:
vim ~/.bash_profile
複製代碼
增長
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
複製代碼
而後運行
source ~/.bash_profile
複製代碼
至此,咱們的環境就搭建完畢了,能夠愉快的開發了。
最近有不少朋友諮詢,大概的問題在這裏整理下,之後陸續更新:
Q: 從github clone下來的版本,爲何執行flutter doctor的時候,等待時間很長?
A: 不建議使用github上面clone的flutter版本搭建環境,那樣的話頗有可能由於網絡緣由致使最終不成功,須要直接從官網下載安裝包安裝,上面有提到,不少人親測下載速度很快,因此放心下。
Q: Android Studio上安裝完flutter和dart插件後,重啓AS,並無看到菜單上有多「新建Flutter工程」的選項
A: 清空Android Studio配置文件,讓Android Studio從新生成配置文件就行。
若是還有疑問,加入qq羣 854192563,咱們一塊兒探討。