謹以此文獻給想少走彎路的人捏肢,筆者參考傳送門走了不少彎路
1 配置環(huán)境變量
由于在國內(nèi)訪問Flutter有時可能會受到限制,F(xiàn)lutter官方為中國開發(fā)者搭建了臨時鏡像市咽,大家可以將如下環(huán)境變量加入到用戶環(huán)境變量中:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
注意: 此鏡像為臨時鏡像,并不能保證一直可用抵蚊,讀者可以參考詳情請參考 Using Flutter in China 以獲得有關(guān)鏡像服務(wù)器的最新動態(tài)施绎。
2 獲取Flutter SDK
首先確定你想把SDK安裝到哪個目錄,在該目錄下創(chuàng)建
development
目錄,名字可以隨便取贞绳。但是為了跟各方面統(tǒng)一谷醉,建議使用名字development
test:~ 用戶名$ pwd
/Users/[用戶名]
test:~ [用戶名]$ mkdir development
獲取Flutter SDK方法一:
去flutter官網(wǎng)下載其最新可用的安裝包,轉(zhuǎn)到下載頁 冈闭。
注意俱尼,F(xiàn)lutter的渠道版本會不停變動,請以Flutter官網(wǎng)為準萎攒。另外遇八,在中國大陸地區(qū),要想正常獲取安裝包列表或下載安裝包躺酒,可能需要翻墻押蚤,讀者也可以去Flutter github項目下去下載安裝包,轉(zhuǎn)到下載頁羹应。
把下載的安裝包放到該目錄中揽碘,然后使用下邊命令解壓
unzip ~/Downloads/flutter_macos_v0.5.1-beta.zip
獲取Flutter SDK方法二:
使用git操作
git clone https://github.com/flutter/flutter.git
3 添加flutter命令相關(guān)工具到path中:
export PATH=`pwd`/flutter/bin:$PATH
注意:此代碼只能暫時針對當前命令行窗口
設(shè)置PATH環(huán)境變量,所以暫時不要關(guān)閉當前命令行窗口
园匹。
添加永久環(huán)境變量
- 1 確定您Flutter SDK的目錄雳刺,您將在步驟4中用到。
- 2 打開(或創(chuàng)建) $HOME/.bash_profile. 文件路徑和文件名可能在您的機器上不同.
- 3 添加以下行并更改裸违。
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=/Users/[你的用戶名,注意修改]/development/flutter/bin:$PATH
- 4 運行命令
source $HOME/.bash_profile
刷新當前終端窗口- 5 隨便再打開一個
命令行窗口
運行flutter命令檢查掖桦,環(huán)境變量是否為全局永久的.有輸出說明生效
例如:
flutter -h
4 運行 flutter doctor檢查依賴環(huán)境
flutter doctor
第一次運行一個flutter命令(如flutter doctor)時,它會下載它自己的依賴項并自行編譯供汛。以后再運行就會快得多枪汪。
該命令檢查您的環(huán)境并在終端窗口中顯示報告。Dart SDK已經(jīng)在捆綁在Flutter里了怔昨,沒有必要單獨安裝Dart雀久。 仔細檢查命令行輸出以獲取可能需要安裝的其他軟件或進一步需要執(zhí)行的任務(wù)(以粗體顯示)
例如:
gcl:~ [用戶名]$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel master, v1.1.1-pre.2, on Mac OS X 10.13.4 17E199, locale
zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
? Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
? Verify that all connected devices have been paired with this computer in
Xcode.
If all devices have been paired, libimobiledevice and ideviceinstaller may
require updating.
To update with Brew, run:
brew update
brew uninstall --ignore-dependencies libimobiledevice
brew uninstall --ignore-dependencies usbmuxd
brew install --HEAD usbmuxd
brew unlink usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
! CocoaPods out of date (1.5.0 is recommended).
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 upgrade:
brew upgrade cocoapods
pod setup
[?] Android Studio (version 3.2)
? Flutter plugin not installed; this adds Flutter specific functionality.
? Dart plugin not installed; this adds Dart specific functionality.
[?] VS Code (version 1.30.0)
[?] Connected device (1 available)
! Doctor found issues in 2 categories.
5 安裝調(diào)試命令
1 安裝 homebrew (如果已經(jīng)安裝了brew,跳過此步驟)
2 打開終端并運行這些命令來安裝用于將Flutter應(yīng)用安裝到iOS設(shè)備的工具
brew update
brew install --HEAD libimobiledevice
brew install ideviceinstaller ios-deploy cocoapods
pod setup
6 安裝Flutter的編輯器
目前Flutter支持的編輯器分別為Android Studio、IntelliJ或VS Code趁舀。
MAC下我還是選擇VS Code赖捌。
6.1 Visual Studio Code (VS Code) 安裝
- VS Code, 安裝1.20.1或更高版本.
6.2 安裝Flutter插件
1 啟動 VS Code
2 調(diào)用 View>Command Palette…
3 輸入 ‘install’, 然后選擇 Extensions: Install Extension action
4 在搜索框輸入 flutter , 在搜索結(jié)果列表中選擇 ‘Flutter’, 然后點擊 Install
5 選擇 ‘OK’ 重新啟動 VS Code