參考
雖然網(wǎng)上有教程,但是過(guò)程中遇到些問題谭确,這些問題教程里并沒有帘营,所以寫這個(gè)文章記錄一下。
1.打開終端
2.clone flutter
命令:
git clone -b beta https://github.com/flutter/flutter.git
到此步終端報(bào)錯(cuò):
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
3.打開(或創(chuàng)建) .bash_profile
1.打開
終端輸入:
open -e .bash_profile
如果不能成功打開琼富,那就創(chuàng)建
2.創(chuàng)建
1.進(jìn)入當(dāng)前用戶的home目錄(默認(rèn)就是)
cd ~
或
cd /Users/用戶名
4.更新環(huán)境變量
打開bash_profile就是為了可以永久的更新環(huán)境變量仪吧,一勞永逸。請(qǐng)看解釋和注意后根據(jù)自己的需要來(lái)將代碼添加到打開的bash_profile鞠眉。
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
解釋: 由于一些flutter
命令需要聯(lián)網(wǎng)獲取數(shù)據(jù)薯鼠,如果您是在國(guó)內(nèi)訪問,由于眾所周知的原因械蹋,直接訪問很可能不會(huì)成功出皇。 上面的PUB_HOSTED_URL
和FLUTTER_STORAGE_BASE_URL
是google為國(guó)內(nèi)開發(fā)者搭建的臨時(shí)鏡像。你也可以不設(shè)置哗戈,如果你能翻墻的話郊艘。如果不能的話可以直接復(fù)制上面的代碼
export PATH= PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin:$PATH
注意:PATH_TO_FLUTTER_GIT_DIRECTORY
為你flutter的路徑,比如在當(dāng)前用戶路徑里。如果不確定纱注,可以點(diǎn)擊mac上面菜單的"前往" --> "個(gè)人"畏浆,然后在此文件夾里找是否有flutter文件夾。如果有的話你的應(yīng)該這樣寫:
export PATH= /Users/用戶名/flutter/bin:$PATH
然后輸入以下命令更新剛剛配置的環(huán)境變量:
source .bash_profile
然后輸入以下命令狞贱,通過(guò)運(yùn)行flutter/bin
命令驗(yàn)證目錄是否在已經(jīng)在PATH中:
echo $PATH
如果看到有flutter那就是配置好了
5.運(yùn)行 flutter doctor
輸入下面這個(gè)命令刻获,來(lái)看還有沒有要安裝的依賴項(xiàng):
flutter doctor
我的話一開始是這個(gè)
讓我更新flutter,我不想看到warning所以立馬更新了瞎嬉。
flutter upgrade
錯(cuò)誤1:
然后就看x了蝎毡,這是我第一個(gè)打叉的地方
[?] 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.
這是讓我安裝android studio并且設(shè)置好$ANDROID_HOME這個(gè)環(huán)境變量。
于是我便按照提示打開https://developer.android.com/studio/index.html氧枣,并且下載安裝了android studio沐兵。
安裝后最好運(yùn)行一下android studio,好安裝andriod sdk便监。運(yùn)行好根據(jù)界面提示點(diǎn)下一步扎谎,如果沒有sdk會(huì)提示安裝,只要點(diǎn)就行了茬贵。記得查看下安裝路徑簿透,一般路徑都是在當(dāng)前用戶的Library文件夾里移袍。
安裝好sdk后解藻,可以把a(bǔ)ndroid studio關(guān)了。
然后打開bash_profile
open -e .bash_profile
在bash_profile里加上
export ANDROID_HOME="/Users/用戶名/Library/Android/sdk" //android sdk目錄葡盗,替換為你自己的
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
更新配置
source .bash_profile
然后運(yùn)行
flutter doctor
看這一項(xiàng)還報(bào)錯(cuò)不螟左。ok還是有報(bào)錯(cuò),報(bào)錯(cuò)如下:
[!] Android toolchain - develop for Android devices (Android SDK 28.0.2)
? Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
根據(jù)提示運(yùn)行:
flutter doctor --android-licenses
然后根據(jù)提示一直y觅够,y到結(jié)束為止胶背。
錯(cuò)誤2:
這是我第二個(gè)打叉的地方
[!] iOS toolchain - develop for iOS devices
? Xcode installation is incomplete; a full installation is necessary for iOS development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
? libimobiledevice and ideviceinstaller are not installed. 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
依舊是根據(jù)提示,我去App Store安裝了xcode喘先。
安裝好后根據(jù)之前的錯(cuò)誤信息運(yùn)行:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
然后:
brew install --HEAD libimobiledevice
再然后:
brew install ideviceinstaller
又然后:
brew install ios-deploy
還然后:
brew install cocoapods
最后然后:
pod setup
進(jìn)行到這我報(bào)錯(cuò)了:
[!] /usr/bin/git clone https://github.com/CocoaPods/Specs.git master --progress
Cloning into 'master'...
remote: Counting objects: 2353094, done.
remote: Compressing objects: 100% (450/450), done.
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
弄個(gè)加速器就可以了钳吟。我用的云墻netfits,有試用窘拯,試用夠下載了红且。如果有更好的加速器歡迎留言。
再運(yùn)行doctor
flutter doctor
ios還有報(bào)錯(cuò):
[!] iOS toolchain - develop for iOS devices (Xcode 9.4.1)
? Missing Xcode dependency: Python module "six".
Install via 'pip install six' or 'sudo easy_install six'.
按照提示輸入'pip install six' 或 'sudo easy_install six'涤姊。然后再運(yùn)行doctor暇番,我這里ios沒有報(bào)錯(cuò)了。就剩錯(cuò)誤3里的報(bào)錯(cuò)思喊。
錯(cuò)誤3:
[?] Android Studio (version 3.1)
? Flutter plugin not installed; this adds Flutter specific functionality.
? Dart plugin not installed; this adds Dart specific functionality.
android studio里還少了兩個(gè)插件壁酬。我們打開andriod studio。
1.點(diǎn)擊preferences
2.搜索plugins
3.搜索flutter
4.點(diǎn)擊安裝
有彈框提示要安裝dart,同意舆乔。等安裝好后重啟andriod studio岳服。
結(jié)語(yǔ)
當(dāng)doctor沒有錯(cuò)誤的時(shí)候,那就是裝好了希俩。但是為了方便開發(fā)派阱,我們還需要對(duì)編輯器做配置。鑒于這個(gè)比較容易斜纪,而且不太出現(xiàn)錯(cuò)誤贫母,所以我就不寫了。大家自己參考文檔來(lái)盒刚。
參考文檔:起步: 配置編輯器
據(jù)量子力學(xué)得到腺劣,點(diǎn)贊這篇文章的人都會(huì)成為歐皇,從此過(guò)著開心幸福的生活??因块。