本文详细介绍在mac下配置flutter环境的每一个步骤,通过图文的方式使得读者快速理解和掌握flutter的环境搭建流程。
下载flutter
推荐去官网下载,速度并不慢,网址:
https://flutter.io/setup-macos/
点击链接:
笔者在写这篇文章时候的链接为:
https://storage.googleapis.com/flutter_infra/releases/beta/macos/flutter_macos_v0.3.2-beta.zip
配置环境变量
先把刚才下载的flutter_macos_v0.3.2-beta.zip解压缩,笔者选择使用的目录是根目录下的app文件夹
配置环境变量,这里笔者使用命令行:
vim ~/.bash_profile
增加一行:
export PATH=/你的flutter文件夹所在位置/flutter/bin:$PATH
保存一下,注意如果这个文件不存在,那么就新建一个。保存完毕之后运行命令:
source ~/.bash_profile
这个时候应该能运行flutter命令了,我们运行命令行:
flutter -h
这个时候应该能展示flutter的命令帮助:
检查环境
运行命令行:
flutter doctor
按照检测结果的说明,如果有[!] ✗ 标志,表示本行检测不通过,需要做一些设置或者安装一些软件。
[!] Android toolchain - develop for Android devices (Android SDK 27.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licens
需要运行
flutter doctor --android-licenses
这里界面会要求输入Y/N,一路输入Y就行了。
✗ ideviceinstaller is not installed; this is used to discover connected iOS devices.
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
运行命令:
brew install --HEAD libimobiledevice
brew install ideviceinstaller
brew install ios-deploy
brew install cocoapods
pod setup
这个步骤有点慢...
当然读者看到的也许和笔者不太一致,请酌情处理。
这里出现了个错误,按照说明,运行:
brew link --overwrite cocoapods
然后继续运行:
pod setup
如果直接运行这个命令,会相当慢,那么我们曲线解决:
cd ~/.cocoapods/repos
git clone https://github.com/CocoaPods/Specs.git
如果还是太慢,那么去
下一份,解压缩到~/.cocoapods/repos/master目录
[✓] Android Studio (version 3.0)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
打开android studio, 打开plugin
输入flutter搜索,点击中间的 Search in repositories
点击install,顺利的话安装完毕之后重启android studio
再次运行
flutter doctor
注意这里有个坑,如果按照指引来做,会一直卡在这里。这里要先重装一下python,运行下面的命令:
brew reinstall python@2
pip install six
再次运行
flutter doctor
至此,我们的环境就搭建完毕了,可以愉快的开发了。如果还有疑问,那么可以加入qq群854192563 我们一起探讨。