flutter环境搭建mac版

本文详细介绍在mac下配置flutter环境的每个步骤,经过图文的方式使得读者快速理解和掌握flutter的环境搭建流程。python

系统环境要求

macOS (64-bit) 硬盘空间: 700 MB (不包含android studio等编辑器工具). 命令行工具:bash, mkdir, rm, git, curl, unzip, which,brew须要保证上述命令在命令行下能使用,android

若是没有安装brew,那么须要先安装:参考:https://segmentfault.com/a/1190000013317511ios

下载flutter

推荐去官网下载,速度并不慢,网址:git

https://flutter.io/setup-macos/github

点击连接:macos

clipboard.png

更新后的连接地址:vim

https://storage.googleapis.com/flutter_infra/releases/beta/macos/flutter_macos_v0.4.4-beta.zipsegmentfault

配置环境变量

先把刚才下载的flutter_macos_v0.3.2-beta.zip解压缩,笔者选择使用的目录是根目录下的app文件夹api

配置环境变量,这里笔者使用命令行:android-studio

vim ~/.bash_profile
复制代码

增长一行:

export PATH=/app/flutter/bin:$PATH
复制代码

保存一下,注意若是这个文件不存在,那么就新建一个。保存完毕以后运行命令:

source ~/.bash_profile
复制代码

这个时候应该能运行flutter命令了,咱们运行命令行:

flutter -h
复制代码

这个时候应该能展现flutter的命令帮助:

clipboard.png

检查环境

运行命令行:

flutter doctor
复制代码

clipboard.png

按照检测结果的说明,若是有[!] ✗ 标志,表示本行检测不经过,须要作一些设置或者安装一些软件。

若是android studio没有安装,那么能够先装下,并使用android studio下载最新的android sdk。android studio下载地址:http://www.android-studio.org/

若是有安装,那么颇有可能看到:

[!] 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
复制代码

clipboard.png

这里界面会要求输入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
复制代码

这个步骤有点慢...

固然读者看到的也许和笔者不太一致,请酌情处理。

clipboard.png

这里出现了个错误,按照说明,运行:

brew link --overwrite cocoapods
复制代码

而后继续运行:

pod setup
复制代码

若是直接运行这个命令,会至关慢,那么咱们曲线解决:

cd ~/.cocoapods/repos
git clone https://github.com/CocoaPods/Specs.git
复制代码

若是仍是太慢,那么去

连接:https://pan.baidu.com/s/1mQ1VvslwwccdoLRi-I0pNg 密码:lax1

下一份,解压缩到~/.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

clipboard.png

输入flutter搜索,点击中间的 Search in repositories

clipboard.png

点击install,顺利的话安装完毕以后重启android studio

再次运行

flutter doctor
复制代码

clipboard.png

注意这里有个坑,若是按照指引来作,会一直卡在这里。这里要先重装一下python,运行下面的命令:

brew reinstall python@2
pip install six
复制代码

再次运行

flutter doctor
复制代码

若是顺利,能够看到环境ok

配置环境变量

若是在国内,你懂的,还须要设置一下pub源,否则就不能愉快的使用别人写的库。

运行:

vim ~/.bash_profile
复制代码

增长

export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
复制代码

而后运行

source ~/.bash_profile
复制代码

至此,咱们的环境就搭建完毕了,能够愉快的开发了。

搭建环境常见问题整理:

最近有不少朋友咨询,大概的问题在这里整理下,之后陆续更新:

Q: 从github clone下来的版本,为何执行flutter doctor的时候,等待时间很长?

A: 不建议使用github上面clone的flutter版本搭建环境,那样的话颇有可能由于网络缘由致使最终不成功,须要直接从官网下载安装包安装,上面有提到,不少人亲测下载速度很快,因此放心下。

Q: Android Studio上安装完flutter和dart插件后,重启AS,并无看到菜单上有多“新建Flutter工程”的选项

A: 清空Android Studio配置文件,让Android Studio从新生成配置文件就行。

若是还有疑问,加入qq群 854192563,咱们一块儿探讨。

相关文章
相关标签/搜索