1、去官网下载sdk
2、配置环境变量
2.1解压你刚才下载的压缩包
在你的文稿下面新建app文件夹,把解压后的flutter文件夹拷贝到app文件夹(因为下面需要用这个路径配置环境变量,你当然也可以放到你电脑习惯用的文件夹)
2.2 用终端打开bash_profile
vim ~/.bash_profile
2.3再打开的bash_profile里面最后添加一行,前面路径是你自己电脑flutter文件的bin目录所在路径
export PATH=/Users/zyw/Documents/app/flutter/bin:$PATH
退出vi编辑器,回到终端
2.4 输入命令,更新环境变量
source ~/.bash_profile
如果没输出任何信息,即说明环境变量成功,如果保存,重新打开上面文件,查看是哪一行报错,删除即可
2.5 运行flutter命令,这个命令会运行很长时间
flutter -h
显示Welcome to Flutter!说明安装成功
3 运行flutter doctor命令,检查flutter的依赖工具,查看缺失什么
flutter doctor
然后看到报错
问题1
[✗] 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
根据上面的提示打开https://developer.android.com/studio/index.html,并且下载安装android studio。
安装成功后设置环境变量(/Users/用户名/Library/Android/sdk是你Android studio的安装目录)
export ANDROID_HOME="/Users/用户名/Library/Android/sdk"
export PATH=${PATH}:${ANDROID_HOME}/tools
export PATH=${PATH}:${ANDROID_HOME}/platform-tools
问题2
[!] Android toolchain - develop for Android devices (Android SDK 28.0.2)
✗ Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
根据提示运行:
flutter doctor --android-licenses
然后根据提示一直y,y到结束为止。
错误3
✗ 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
根据上面提示运行
brew update
brew install --HEAD usbmuxd
brew link usbmuxd
brew install --HEAD libimobiledevice
brew install ideviceinstaller
brew install ios-deploy
警告
! CocoaPods out of date (1.6.0 is recommended).
CocoaPods is used to retrieve the iOS and macOS platform side's plugin
code that responds to your plugin usage on the Dart side.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins
To upgrade:
brew upgrade cocoapods
pod setup
cocoapods需要升级,运行命令:
brew upgrade cocoapods
pod setup
错误4
✓] 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缺少插件。我们打开andriod studio
1.点击preferences
2.搜索plugins
3.搜索flutter
4.点击安装
有弹框提示要安装dart,同意。等安装好后重启andriod studio。
问题5
Flutter requires Android SDK 28 and the Android BuildTools 28.0.3
To update using sdkmanager, run:
"/Users/用户名/Library/Android/sdk/tools/bin/sdkmanager"
"platforms;android-28" "build-tools;28.0.3"
or visit https://flutter.dev/setup/#android-setup for detailed
instructions.
问题6
⡿ideviceinfo returned an error:
ERROR: Could not connect to lockdownd, error code -17
运行命令
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