Mac搭建Fluter应用环境
1、创建一个路径。例如我创建是:
/Users/chenghui/
然后创建一个文件夹:
development
把下载好的Fluter 解压到当前目录下: development
/Users/chenghui/development
2、当你看官网的时候,Mac环境配置 许多小伙伴都是卡在了配置环境变量这里。
基本我们都要创建一个 .zshrc文件,默认情况下不存在。
创建步骤:
1、开放终端
键入
touch ~/.zshrc 以创建相应的文件。(该touch 命令将在当前目录中创建.zshrc,但它将被隐藏)
击中 return
2、要查看/打开,~/.zshrc您可以执行以下两项操作之一:
2.1、打开查找器 => 按 Cmd + Shift + . (显示或隐藏文件,不要随便删除这些隐藏文件)
============ OR ====================
2.2、打开终端 => 类型 open ~/.zshrc
3、配置永久路径
但你打开 open ~/.zshrc
// 默认是这样子的:
export PATH="$PATH:[PATH_TO_FLUTTER_GIT_DIRECTORY]/flutter/bin"
把 [PATH_TO_FLUTTER_GIT_DIRECTORY] 替换成你自己的目录路径。
这里我的是:/Users/chenghui/development
export PATH="$PATH:/Users/chenghui/development/flutter/bin"
输入后 ~等待~~ 回车的效果:
chenghui@chenghuideMacBook-Pro-2 development % open ~/.zshrc
chenghui@chenghuideMacBook-Pro-2 development % source $HOME/.bash_profile
[Chenghui-\u \W]$ echo $PATH
/Users/chenghui/.rbenv/shims:/Users/chenghui/.rbenv/bin:/usr/local/opt/openssl/bin:/Users/chenghui/.rbenv/shims:/Users/chenghui/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/chenghui/.rvm/bin:/Users/chenghui/flutter/bin:/Users/chenghui/development/flutter/bin
[Chenghui-\u \W]$
如果选择了:(开发二进制文件预下载(可选操作))~~~ 等待.....
[Chenghui-\u \W]$ flutter precache
╔════════════════════════════════════════════════════════════════════════════╗
║ Welcome to Flutter! - https://flutter.dev ║
║ ║
║ The Flutter tool uses Google Analytics to anonymously report feature usage ║
║ statistics and basic crash reports. This data is used to help improve ║
║ Flutter tools over time. ║
║ ║
║ Flutter tool analytics are not sent on the very first run. To disable ║
║ reporting, type 'flutter config --no-analytics'. To display the current ║
║ setting, type 'flutter config'. If you opt out of analytics, an opt-out ║
║ event will be sent, and then no further information will be sent by the ║
║ Flutter tool. ║
║ ║
║ By downloading the Flutter SDK, you agree to the Google Terms of Service. ║
║ Note: The Google Privacy Policy describes how data is handled in this ║
║ service. ║
║ ║
║ Moreover, Flutter includes the Dart SDK, which may send usage metrics and ║
║ crash reports to Google. ║
║ ║
║ Read about data we send with crash reports: ║
║ https://github.com/flutter/flutter/wiki/Flutter-CLI-crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://www.google.com/intl/en/policies/privacy/ ║
╚════════════════════════════════════════════════════════════════════════════╝
继续等待....
Downloading Android Maven dependencies...
(This is taking an unexpectedly long time.) ⣾
最终下载是这样子吧:
Downloading Android Maven dependencies...
272.6s (!)
接着,查看当前是否还要安装其他依赖:flutter doctor
[Chenghui-\u \W]$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.3 19D76,
locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
! Some Android licenses not accepted. To resolve this, run: flutter doctor
--android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
[!] Android Studio (version 3.5)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] IntelliJ IDEA Ultimate Edition (version 2018.2.5)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.44.2)
[!] Connected device
! No devices available
! Doctor found issues in 4 categories.
[Chenghui-\u \W]$
它说我的Android Studio 和 IntelliJ IDEA Ultimate Edition 没有安装插件。但是Xcode 和 VS Code 是可以的。
4、Xcode 和 Android Studio 的安装基本跟着官网就可以了...... 忽略!!!
5、使用终端创建一个应用:
[Chenghui-\u \W]$ flutter create my_app
又是漫长的等待.... This is taking an unexpectedly long time.
$ cd my_app
$ flutter run
链接:https://www.jianshu.com/p/637a20452582