這篇文章本來是不打算發(fā)的,因?yàn)榫W(wǎng)上教程太多了,而且都大同小異。今天在做筆記時(shí)突然想起來,覺得還是發(fā)出來,希望能對(duì)其他遇到相同問題的人有所幫助。
獲取Flutter SDK
第一步
git clone -b beta https://github.com/flutter/flutter.git
export PATH= PATH_TO_FLUTTER_GIT_DIRECTORY/flutter/bin:$PATH
export ANDROID_HOME="/Users/用戶名/Documents/android_sdk" //android sdk目錄,替換為你自己的即可
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
export PUB_HOSTED_URL=https://pub.flutter-io.cn //國內(nèi)用戶需要設(shè)置
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn //國內(nèi)用戶需要設(shè)置
注意:__ PATH_TO_FLUTTER_GIT_DIRECTORY __為你flutter的路徑,比如“~/document/code”
第二步
- 運(yùn)行 source .profile 刷新當(dāng)前終端窗口.
- 執(zhí)行
echo $PATH,查看環(huán)境變量是否添加成功
第三步(運(yùn)行Flutter)
flutter doctor
注意:這里可能會(huì)提示有錯(cuò),比如:
1、Android SDK 路徑有誤,或者ANDROID_HOME環(huán)境變量沒設(shè)置
[-] Android toolchain - develop for Android devices
? Android SDK at /Users/obiwan/Library/Android/sdk
? Android SDK is missing command line tools; download from https://goo.gl/XxQghQ
? Try re-installing or updating your Android SDK,
visit https://flutter.io/setup/#android-setup for detailed instructions.
2、報(bào) Downloaded executables cannot execute on host. 錯(cuò)誤,同時(shí)也給出了解決方案
1、在Debian/Ubantu/Mint上,執(zhí)行 sudo apt-get install lib32stdc++6
2、在Fedora上,執(zhí)行 dnf install libstdc++.i686
3、在Arch上,執(zhí)行 pacman -S lib32-libstdc++5
查了一下,出現(xiàn)這個(gè)錯(cuò)誤是因?yàn)樵?4位的機(jī)器上無法執(zhí)行32位的文件,所以需要安裝個(gè)兼容庫??
然而在安裝的過程中也出現(xiàn)了問題(后來切換到root上安裝又可以了,什么鬼?)
3、 Some Android licenses not accepted 錯(cuò)誤,解決方案也給出了
執(zhí)行 flutter doctor --android-licenses,然后全部接受協(xié)議即可
4、 Flutter plugin not installed,Dart plugin not installed 錯(cuò)誤,打開Android studio裝上就完了
5、提示沒安裝Android studio,給Flutter指定Android Studio的安裝路徑即可,例如執(zhí)行flutter config --android-studio-dir=/<user name>/Android Studio
注意,每次安裝完確實(shí)的依賴后都執(zhí)行 Flutter doctor 查看是否安裝成功
附兩個(gè)學(xué)習(xí)網(wǎng)站:
https://flutter.dev/docs/get-started/install
https://flutterchina.club
更新 2019.04.18
配置IOS開發(fā)環(huán)境
1、安裝Xcode
2、安裝brew(如果mac上沒有安裝的話)
2、執(zhí)行flutter doctor,按提示執(zhí)行響應(yīng)的命令,如
**?**** 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 with Brew:**
** brew install ios-deploy**
**?**** Brew can be used to install tools for iOS device development.**
** Download brew at [https://brew.sh/.](https://brew.sh/)**
期間,可能會(huì)出現(xiàn)
chenwenhuideMacBook-Pro:~ chenwenhui$ brew install --HEAD libimobiledevice
Updating Homebrew...
==> Cloning https://git.libimobiledevice.org/libimobiledevice.git
Cloning into '/Users/chenwenhui/Library/Caches/Homebrew/libimobiledevice--git'...
fatal: unable to access 'https://git.libimobiledevice.org/libimobiledevice.git/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
Error: An exception occurred within a child process:
DownloadError: Failed to download resource "libimobiledevice"
Failure while executing; `git clone --branch master https://git.libimobiledevice.org/libimobiledevice.git /Users/chenwenhui/Library/Caches/Homebrew/libimobiledevice--git` exited with 128\. Here's the output:
Cloning into '/Users/chenwenhui/Library/Caches/Homebrew/libimobiledevice--git'...
fatal: unable to access 'https://git.libimobiledevice.org/libimobiledevice.git/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
解決辦法:翻墻,更新brew 軟件源,多試幾次
解決之后,在執(zhí)行flutter doctor,按提示執(zhí)行響應(yīng)命令
**?**** ios-deploy not installed. To install with Brew:**
** 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**
安裝完后,在執(zhí)行flutter doctor