1、安装git,可以去先App Store下载Xcode,安装好Xcode默认会安装好git
2、去flutter官网下载其最新可用的安装包,最好下载stable稳定版本,下载链接:https://flutter.dev/docs/development/tools/sdk/releases#macos
3、解压安装包到你想安装的目录
cd ~/development
unzip ~/Downloads/flutter_macos_v0.5.1-beta.zip
4、添加flutter相关工具到path中,在终端输入命令【open ~/.zshrc】,如果报错【The file /Users/personal/.zshrc does not exist.】,说明还没有创建.zshrc文件,需要先运行【vim ~/.zshrc】创建.zshrc文件,然后再运行【open ~/.zshrc】,具体操作如下所示:
personal@MacBook-Pro ~ % open ~/.zshrc
The file /Users/personal/.zshrc does not exist.
personal@MacBook-Pro ~ % vim ~/.zshrc
personal@MacBook-Pro ~ % open ~/.zshrc
然后将以下配置复制进.zshrc里边
注意: export PATH=【此处为下载的flutter路径】/bin:$PATH
export PATH=/Users/personal/Desktop/project/flutter/bin:$PATH
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
具体显示如下图所示:
然后再运行以下命令保存.zshrc文件:
personal@MacBook-Pro ~ % source ~/.zshrc
5、终端路径指向下载的flutter路径,然后运行【flutter doctor】命令查看是否需要安装其它依赖项来完成安装
如下图所示:
personal@MacBook-Pro ~ % cd /Users/personal/Desktop/project/flutter
personal@MacBook-Pro flutter % flutter doctor
╔════════════════════════════════════════════════════════════════════════════╗
║ 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://flutter.dev/docs/reference/crash-reporting ║
║ ║
║ See Google's privacy policy: ║
║ https://policies.google.com/privacy ║
╚════════════════════════════════════════════════════════════════════════════╝
Running "flutter pub get" in flutter_tools... 6.7s
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-arm, locale zh-Hans-CN)
[✗] 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.dev/docs/get-started/install/macos#android-setup for detailed
instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
[!] Xcode - develop for iOS and macOS
✗ CocoaPods not installed.
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 install see https://guides.cocoapods.org/using/getting-started.html#installation for
instructions.
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] Connected device (1 available)
! Doctor found issues in 3 categories.
personal@chenmengdideMacBook-Pro flutter %
6、1. 安装 homebrew (如果已经安装了brew,跳过此步骤).
使用以下命令安装会报错:
personal@MacBook-Pro project % /bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)”
curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused
/bin/bash: “”: command not found
可以使用以下命令,序列号选择中科大(1)的:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
运行结果:
personal@MacBook-Pro project % /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
开始执行Brew自动安装程序
[[email protected]]
['2021-11-06 16:54:24']['11.6']
https://zhuanlan.zhihu.com/p/111014448
请选择一个下载镜像,例如中科大,输入1回车。
源有时候不稳定,如果git克隆报错重新运行脚本选择源。cask非必须,有部分人需要。
1、中科大下载源 2、清华大学下载源 3、北京外国语大学下载源 4、腾讯下载源(不推荐) 5、阿里巴巴下载源(不推荐 缺少cask源)
请输入序号: 1
你选择了中国科学技术大学下载源
!!!此脚本将要删除之前的brew(包括它下载的软件),请自行备份。
->是否现在开始执行脚本(N/Y) Y
--> 脚本开始执行
Mac os设置开机密码方法:
(设置开机密码:在左上角苹果图标->系统偏好设置->用户与群组->更改密码)
(如果提示This incident will be reported. 在用户与群组中查看是否管理员)
==> 通过命令删除之前的brew、创建一个新的Homebrew文件夹
请输入开机密码,输入过程不显示,输入完后回车
Password:
开始执行
-> 创建文件夹 /opt/homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew
此步骤成功
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /opt/homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown personal /opt/homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew
git version 2.30.1 (Apple Git-130)
下载速度觉得慢可以ctrl+c或control+c重新运行脚本选择下载源
==> 克隆Homebrew基本文件
未发现Git代理(属于正常状态)
Cloning into '/opt/homebrew'...
remote: Enumerating objects: 203986, done.
remote: Total 203986 (delta 0), reused 0 (delta 0) | 19.87 MiB/s
Receiving objects: 100% (203986/203986), 53.49 MiB | 19.23 MiB/s, done.
Resolving deltas: 100% (151877/151877), done.
此步骤成功
--创建Brew所需要的目录
运行代码 ==> /usr/bin/sudo /bin/chmod u+rwx /opt/homebrew/bin /opt/homebrew/bin/brew
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /opt/homebrew/bin /opt/homebrew/bin/brew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown personal /opt/homebrew/bin /opt/homebrew/bin/brew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
运行代码 ==> /usr/bin/sudo /usr/sbin/chown personal /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew/etc /opt/homebrew/include /opt/homebrew/lib /opt/homebrew/sbin /opt/homebrew/share /opt/homebrew/var /opt/homebrew/opt /opt/homebrew/share/zsh /opt/homebrew/share/zsh/site-functions /opt/homebrew/var/homebrew /opt/homebrew/var/homebrew/linked /opt/homebrew/Cellar /opt/homebrew/Caskroom /opt/homebrew/Frameworks
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R personal:admin /opt/homebrew
运行代码 ==> /usr/bin/sudo /bin/mkdir -p /Users/personal/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/personal/Library/Caches/Homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown -R personal /Users/personal/Library/Caches/Homebrew
--依赖目录脚本运行完成
==> 创建brew的替身
==> 克隆Homebrew Core
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Enumerating objects: 1089893, done.
remote: Total 1089893 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1089893/1089893), 445.93 MiB | 13.92 MiB/s, done.
Resolving deltas: 100% (757156/757156), done.
此步骤成功
==> 克隆Homebrew Cask 图形化软件
此处如果显示Password表示需要再次输入开机密码,输入完后回车
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 653794, done.
remote: Total 653794 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (653794/653794), 296.74 MiB | 14.27 MiB/s, done.
Resolving deltas: 100% (467494/467494), done.
此步骤成功
==> 克隆Homebrew services 管理服务的启停
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 1141, done.
remote: Total 1141 (delta 0), reused 0 (delta 0), pack-reused 1141
Receiving objects: 100% (1141/1141), 331.50 KiB | 3.31 MiB/s, done.
Resolving deltas: 100% (484/484), done.
此步骤成功
==> 配置国内镜像源HOMEBREW BOTTLE
sed: /Users/personal/.zprofile: No such file or directory
环境变量写入->/Users/personal/.zprofile
此步骤成功
运行代码 ==> /usr/bin/sudo /bin/chmod -R a+rwx /opt/homebrew
运行代码 ==> /usr/bin/sudo /usr/sbin/chown personal /opt/homebrew
运行代码 ==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew
==> 安装完成,brew版本
Homebrew 3.3.2-64-gcb24983-dirty
Homebrew/homebrew-core (git revision 06b92d7448a; last commit 2021-11-06)
Homebrew/homebrew-cask (git revision 014a9637a1; last commit 2021-11-06)
Brew前期配置成功
电脑系统版本:11.6
All user-space services OK, nothing cleaned...
==> brew update-reset
==> Fetching /opt/homebrew...
==> Resetting /opt/homebrew...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.
==> Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-cask...
==> Resetting /opt/homebrew/Library/Taps/homebrew/homebrew-cask...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.
==> Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-core...
==> Resetting /opt/homebrew/Library/Taps/homebrew/homebrew-core...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.
==> Fetching /opt/homebrew/Library/Taps/homebrew/homebrew-services...
==> Resetting /opt/homebrew/Library/Taps/homebrew/homebrew-services...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Reset branch 'master'
Your branch is up to date with 'origin/master'.
Brew自动安装程序运行完成
国内地址已经配置完成
桌面的Old_Homebrew文件夹,大致看看没有你需要的可以删除。
初步介绍几个brew命令
本地软件库列表:brew ls
查找软件:brew search google(其中google替换为要查找的关键字)
查看brew版本:brew -v 更新brew版本:brew update
安装cask软件:brew install --cask firefox 把firefox换成你要安装的
欢迎右键点击下方地址-打开URL 来给点个赞
https://zhuanlan.zhihu.com/p/111014448
重启终端 或者 运行 source /Users/personal/.zprofile 否则可能无法使用
按照提示继续运行以下命令:
personal@MacBook-Pro project % source /Users/personal/.zprofile
安装成功,查看brew版本:
personal@MacBook-Pro project % brew -v
Homebrew 3.3.2-64-gcb24983
7、安装Cocoapods:
brew update
brew install --HEAD libimobiledevice
brew install ideviceinstaller ios-deploy cocoapods
pod setup
此时运行pod search会报错:
personal@MacBook-Pro project % pod search Masonry
Setup completed
[!] Unable to find a pod with name, author, summary, or description matching `Masonry`
解决办法可参考:https://www.jianshu.com/p/02b8b698ff24
8、下载Android studio ,下载链接:https://developer.android.google.cn/studio/
M1下载Apple chip版本,如下图所示:
打开Android studio:
打开Android studio --> Preferences,配置Android SDK,如下图所示:
Android Studio 打开Preferences下载Dart和Flutter插件,如下如所示
9、运行flutter doctor查看配置:
personal@MacBook-Pro master % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-arm, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] Connected device (1 available)
! Doctor found issues in 1 category.
按照提示运行【flutter doctor --android-licenses】
如果报以下错误:
personal@MacBook-Pro master % flutter doctor --android-licenses
Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are
installed to resolve this.
解决办法:
设置之后再运行【flutter doctor --android-licenses】命令:
personal@MacBook-Pro master % flutter doctor --android-licenses
6 of 7 SDK package licenses not accepted. 100% Computing updates...
Review licenses that have not been accepted (y/N)? y
1/6: License android-googletv-license:
---------------------------------------
Terms and Conditions
This is the Google TV Add-on for the Android Software Development Kit License Agreement.
1. Introduction
..............................................................一直选y就可以了
All SDK package licenses accepted
最后运行【flutter doctor 】命令,全部配置完成
personal@MacBook-Pro master % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-arm, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] Connected device (1 available)
• No issues found!
打开Android Studio创建一个Flutter项目,打开Preferences,配置Dart和Flutter路径,如下图所示:
到此,flutter环境配置完成。