安裝之前的環(huán)境:
pod: 1.5.3
xcode : 10.1
1. 獲取Flutter SDK
通過官網(wǎng)地址:https://flutter.io/sdk-archive/#windows 下載最新的SDK
2. 配置環(huán)境變量
進入文件.bash_profile ,如果沒有就通過命令創(chuàng)建一個 touch .bash_profile
xia:~ mac$ vim .bash_profile
在文件中加入一行
export PATH={pwd}/flutter/bin:$PATH
其中pwd是下載的flutter所在的文件路徑
例如,我的flutter下載之后放在了~/flutter路徑下,那么我的就是
export PATH=~/flutter/bin:$PATH
接下來運行source命令,更新配置
xia:~ mac$ source .bash_profile
3. 運行Flutter
執(zhí)行命令
xia:~ mac$ flutter -h
應(yīng)該會出現(xiàn)' Welcome to Flutter! '的歡迎語,具體命令輸出就不粘貼了
4. 檢查Flutter環(huán)境
執(zhí)行命令flutter doctor
xia:~ mac$ flutter doctor
此時我的窗口出現(xiàn)了下面的輸出,顯示[?][!]就是錯誤和警告的地方,接下來按照提示一步一步解決
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.2 18C54, locale
zh-Hans-CN)
[?] Android toolchain - develop for Android devices
? Unable to locate Android SDK.
Install Android Studio from:
https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK
components.
(or visit https://flutter.io/setup/#android-setup for detailed
instructions).
If Android SDK has been installed to a custom location, set ANDROID_HOME
to that location.
You may also want to add it to your PATH environment variable.
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
? libimobiledevice and ideviceinstaller are not installed. To install with
Brew, run:
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
? ios-deploy not installed. To install:
brew install ios-deploy
[!] Android Studio (not installed)
[!] VS Code (version 1.28.2)
? Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[?] Connected device (1 available)
! Doctor found issues in 4 categories.
1. 安裝Android Studio、Android SDK、Flutter插件、Dark插件
此時并未安裝Android SDK。第一步安裝Android Studio之后,啟動,會彈出一個框,點擊cancel,接下來Android Studio會自動安裝SDK。安裝好了之后,重啟Android Studio,在Android Studio-Preference-Plugins中安裝Fluuter和Dark插件
再次執(zhí)行 flutter doctor 命令
[?] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.2 18C54, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
? Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
? libimobiledevice and ideviceinstaller are not installed. To install with
Brew, run:
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
[!] Android Studio (version 3.3)
? Flutter plugin not installed; this adds Flutter specific functionality.
? Dart plugin not installed; this adds Dart specific functionality.
[?] VS Code (version 1.28.2)
[?] Connected device (1 available)
安裝了Flutter和Dark插件,還是報下邊的錯誤
? Flutter plugin not installed; this adds Flutter specific functionality.
? Dart plugin not installed; this adds Dart specific functionality.
我的解決辦法是執(zhí)行了一下
flutter doctor -v
報? Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses錯誤的話就執(zhí)行一下
flutter doctor --android-licenses就好,確認(rèn)一下協(xié)議,輸入y確認(rèn)下就行
2. 安裝iOS toolchain
這個比較簡單,按照提示步驟一步一步來
[!] iOS toolchain - develop for iOS devices (Xcode 10.1)
? libimobiledevice and ideviceinstaller are not installed. To install with
Brew, run:
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
在這個過程中我安裝libimobiledevice的時候報了下邊這個錯誤,解決辦法是執(zhí)行 pod setup,然后多試幾次,多試幾次?。?!
Cloning into '/Users/mac/Library/Caches/Homebrew/libimobiledevice--git'...
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
最后再執(zhí)行 flutter doctor 輸出以下信息,說明全部安裝完畢,恭喜~
Doctor summary (to see all details, run flutter doctor -v):
[?] Flutter (Channel stable, v1.2.1, on Mac OS X 10.14.2 18C54, locale zh-Hans-CN)
[?] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[?] iOS toolchain - develop for iOS devices (Xcode 10.1)
[?] Android Studio (version 3.3)
[?] VS Code (version 1.28.2)
[?] Connected device (1 available)
? No issues found!