一、下载Flutter SDK
两种下载方式:
第一种:在Flutter官网下载。
第二种:在GitHub下载源码,可以直接download zip包,也可以使用git命令行克隆,命令行如下:
git clone -b beta https://github.com/flutter/flutter.git
注:下载完成后,记得解压。
二、配置Flutter SDK
- 进入mac终端,直接输入命令
vim ~/.bash_profile
; - 敲键盘字母“i”(代表INSERT);
- 粘贴以下代码,将镜像加入到环境变量中。
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
export PATH=刚下载的flutter文件夹外层路径/flutter/bin:$PATH
输入后按“esc”退出键盘输入,再敲:wq
,写入并退出。
其中第三点示例如下(以我本机路径为例):
export PATH=~/flutter/flutter/bin:$PATH
- 执行以下代码
source ~/.bash_profile
(类似于刷新终端的功效,以前没有过.bash_profile的需要执行此步) - 此时,可以运行flutter命令,检测是否配置成功
flutter -h
,如果成功,应该会有如下显示:
- 运行
flutter doctor
,检测flutter环境,此步就是根据检测结果,将所有的❌都变成✅。
注:以下为我遇到的❌:
问题一:
[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
就执行加粗的那段代码,即flutter doctor --android-licenses
,之后有很多让你确认的地方(输入y/N),一路输入“y”即可。
问题二:
[✗] 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 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
✗ 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
问题描述:没有完整的iOS开发环境(😂我是Android开发)
解决方案:
- 下载并安装XCode
- 逐条执行终端中加粗的命令行
问题三:
[✓] Android Studio (version 3.2)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
问题描述:需要安装两个插件:
Flutter插件: 支持Flutter开发工作流 (运行、调试、热重载等).
Dart插件: 提供代码分析 (输入代码时进行验证、代码补全等).
解决方案:
- 启动Android Studio.
- 打开插件首选项 (Preferences>Plugins on macOS, File>Settings>Plugins on Windows & Linux).
- 选择 Browse repositories…, 选择 Flutter 插件并点击 install.
- 重启Android Studio后插件生效.
问题四:
[!] Connected device
! No devices available
连接上移动设备(处于开发者模式)/模拟器即可
网友评论