1、安裝git吆你,可以去先App Store下載Xcode妇多,安裝好Xcode默認(rèn)會(huì)安裝好git
2砌梆、去flutter官網(wǎng)下載其最新可用的安裝包咸包,最好下載stable穩(wěn)定版本烂瘫,下載鏈接:https://flutter.dev/docs/development/tools/sdk/releases#macos
3奇适、解壓安裝包到你想安裝的目錄
cd ~/development
unzip ~/Downloads/flutter_macos_v0.5.1-beta.zip
4嚷往、添加flutter相關(guān)工具到path中皮仁,在終端輸入命令【open ~/.zshrc】贷祈,如果報(bào)錯(cuò)【The file /Users/personal/.zshrc does not exist.】势誊,說(shuō)明還沒(méi)有創(chuàng)建.zshrc文件粟耻,需要先運(yùn)行【vim ~/.zshrc】創(chuàng)建.zshrc文件眉踱,然后再運(yùn)行【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
然后將以下配置復(fù)制進(jìn).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
具體顯示如下圖所示:
然后再運(yùn)行以下命令保存.zshrc文件:
personal@MacBook-Pro ~ % source ~/.zshrc
5、終端路徑指向下載的flutter路徑矮冬,然后運(yùn)行【flutter doctor】命令查看是否需要安裝其它依賴項(xiàng)來(lái)完成安裝
如下圖所示:
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 (如果已經(jīng)安裝了brew,跳過(guò)此步驟).
使用以下命令安裝會(huì)報(bào)錯(cuò):
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
可以使用以下命令恢筝,序列號(hào)選擇中科大(1)的:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
運(yùn)行結(jié)果:
personal@MacBook-Pro project % /bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
開(kāi)始執(zhí)行Brew自動(dòng)安裝程序
[cunkai.wang@foxmail.com]
['2021-11-06 16:54:24']['11.6']
https://zhuanlan.zhihu.com/p/111014448
請(qǐng)選擇一個(gè)下載鏡像撬槽,例如中科大侄柔,輸入1回車移剪。
源有時(shí)候不穩(wěn)定薪者,如果git克隆報(bào)錯(cuò)重新運(yùn)行腳本選擇源言津。cask非必須纺念,有部分人需要陷谱。
1、中科大下載源 2渣窜、清華大學(xué)下載源 3乔宿、北京外國(guó)語(yǔ)大學(xué)下載源 4详瑞、騰訊下載源(不推薦) 5坝橡、阿里巴巴下載源(不推薦 缺少cask源)
請(qǐng)輸入序號(hào): 1
你選擇了中國(guó)科學(xué)技術(shù)大學(xué)下載源
>谩V搿赖阻!此腳本將要?jiǎng)h除之前的brew(包括它下載的軟件)政供,請(qǐng)自行備份朽基。
->是否現(xiàn)在開(kāi)始執(zhí)行腳本(N/Y) Y
--> 腳本開(kāi)始執(zhí)行
Mac os設(shè)置開(kāi)機(jī)密碼方法:
(設(shè)置開(kāi)機(jī)密碼:在左上角蘋果圖標(biāo)->系統(tǒng)偏好設(shè)置->用戶與群組->更改密碼)
(如果提示This incident will be reported. 在用戶與群組中查看是否管理員)
==> 通過(guò)命令刪除之前的brew稼虎、創(chuàng)建一個(gè)新的Homebrew文件夾
請(qǐng)輸入開(kāi)機(jī)密碼霎俩,輸入過(guò)程不顯示打却,輸入完后回車
Password:
開(kāi)始執(zhí)行
-> 創(chuàng)建文件夾 /opt/homebrew
運(yùn)行代碼 ==> /usr/bin/sudo /bin/mkdir -p /opt/homebrew
此步驟成功
運(yùn)行代碼 ==> /usr/bin/sudo /bin/chmod -R a+rwx /opt/homebrew
運(yùn)行代碼 ==> /usr/bin/sudo /usr/sbin/chown personal /opt/homebrew
運(yùn)行代碼 ==> /usr/bin/sudo /usr/bin/chgrp admin /opt/homebrew
git version 2.30.1 (Apple Git-130)
下載速度覺(jué)得慢可以ctrl+c或control+c重新運(yùn)行腳本選擇下載源
==> 克隆Homebrew基本文件
未發(fā)現(xiàn)Git代理(屬于正常狀態(tài))
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.
此步驟成功
--創(chuàng)建Brew所需要的目錄
運(yùn)行代碼 ==> /usr/bin/sudo /bin/chmod u+rwx /opt/homebrew/bin /opt/homebrew/bin/brew
運(yùn)行代碼 ==> /usr/bin/sudo /bin/chmod g+rwx /opt/homebrew/bin /opt/homebrew/bin/brew
運(yùn)行代碼 ==> /usr/bin/sudo /usr/sbin/chown personal /opt/homebrew/bin /opt/homebrew/bin/brew
運(yùn)行代碼 ==> /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
運(yùn)行代碼 ==> /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
運(yùn)行代碼 ==> /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
運(yùn)行代碼 ==> /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
運(yùn)行代碼 ==> /usr/bin/sudo /usr/sbin/chown -R personal:admin /opt/homebrew
運(yùn)行代碼 ==> /usr/bin/sudo /bin/mkdir -p /Users/personal/Library/Caches/Homebrew
運(yùn)行代碼 ==> /usr/bin/sudo /bin/chmod g+rwx /Users/personal/Library/Caches/Homebrew
運(yùn)行代碼 ==> /usr/bin/sudo /usr/sbin/chown -R personal /Users/personal/Library/Caches/Homebrew
--依賴目錄腳本運(yùn)行完成
==> 創(chuàng)建brew的替身
==> 克隆Homebrew Core
此處如果顯示Password表示需要再次輸入開(kāi)機(jī)密碼,輸入完后回車
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表示需要再次輸入開(kāi)機(jī)密碼捌肴,輸入完后回車
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 管理服務(wù)的啟停
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.
此步驟成功
==> 配置國(guó)內(nèi)鏡像源HOMEBREW BOTTLE
sed: /Users/personal/.zprofile: No such file or directory
環(huán)境變量寫入->/Users/personal/.zprofile
此步驟成功
運(yùn)行代碼 ==> /usr/bin/sudo /bin/chmod -R a+rwx /opt/homebrew
運(yùn)行代碼 ==> /usr/bin/sudo /usr/sbin/chown personal /opt/homebrew
運(yùn)行代碼 ==> /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前期配置成功
電腦系統(tǒng)版本: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自動(dòng)安裝程序運(yùn)行完成
國(guó)內(nèi)地址已經(jīng)配置完成
桌面的Old_Homebrew文件夾饥悴,大致看看沒(méi)有你需要的可以刪除西设。
初步介紹幾個(gè)brew命令
本地軟件庫(kù)列表:brew ls
查找軟件:brew search google(其中g(shù)oogle替換為要查找的關(guān)鍵字)
查看brew版本:brew -v 更新brew版本:brew update
安裝cask軟件:brew install --cask firefox 把firefox換成你要安裝的
歡迎右鍵點(diǎn)擊下方地址-打開(kāi)URL 來(lái)給點(diǎn)個(gè)贊
https://zhuanlan.zhihu.com/p/111014448
重啟終端 或者 運(yùn)行 source /Users/personal/.zprofile 否則可能無(wú)法使用
按照提示繼續(xù)運(yùn)行以下命令:
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
此時(shí)運(yùn)行pod search會(huì)報(bào)錯(cuò):
personal@MacBook-Pro project % pod search Masonry
Setup completed
[!] Unable to find a pod with name, author, summary, or description matching `Masonry`
解決辦法可參考:http://www.reibang.com/p/02b8b698ff24
8叉弦、下載Android studio 藻糖,下載鏈接:https://developer.android.google.cn/studio/
M1下載Apple chip版本巨柒,如下圖所示:
打開(kāi)Android studio:
打開(kāi)Android studio --> Preferences珍坊,配置Android SDK正罢,如下圖所示:
Android Studio 打開(kāi)Preferences下載Dart和Flutter插件翻具,如下如所示
9叹洲、運(yùn)行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.
按照提示運(yùn)行【flutter doctor --android-licenses】
如果報(bào)以下錯(cuò)誤:
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.
解決辦法:
設(shè)置之后再運(yùn)行【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
最后運(yùn)行【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!
打開(kāi)Android Studio創(chuàng)建一個(gè)Flutter項(xiàng)目帜篇,打開(kāi)Preferences笙隙,配置Dart和Flutter路徑,如下圖所示:
到此,flutter環(huán)境配置完成坏快。