Mac上安装配置Flutter时遇到的问题以及解决方案

Flutter下载地址
Flutter环境搭建教程

配置Flutter

根据教程配置环境后,执行flutter doctor命令时,出现如下错误:

1.错误1(xcrun: error)

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

解决方案:
需要执行xcode-select --install命令下载安装xcode-select
参考博客:解决报错:xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcru

2.错误2(Android相关)

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
✗ 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.

解决方案:
第一条按提示,Android平台需要下载安装cmdline-tools,进入Android Studio-打开SDK Manager->SDK Tools->勾选Android SDK Command-lines Tools->确认进行下载安装。

第二条按提示,执行下面指令,授予证书。

flutter doctor --android-licenses

3.错误3(Xcode相关)

[✗] Xcode - develop for iOS and macOS
✗ Xcode installation is incomplete; a full installation is necessary for iOS
development.
Download at: https://developer.apple.com/xcode/download/
Or install Xcode via the App Store.
Once installed, run:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
✗ CocoaPods installed but not working.
You appear to have CocoaPods installed but it is not working.
This can happen if the version of Ruby that CocoaPods was installed with
is different from the one being used to invoke it.
This can usually be fixed by re-installing CocoaPods.

解决方案:
此问题是由于Xcode未安装(未在应用程序中找到Xcode)或者安装了beta版本的Xcode-beta,需要将beta版本的程序移动到mac的应用程序中,并改名为Xcode。

4.安装成功

解决如上错误后,重新执行flutter doctor命令,成功后如下显示:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.2, on macOS 13.0 22A5266r darwin-x64, locale
zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.68.0-insider)
[✓] VS Code (version 1.51.0-insider)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
• No issues found!
在这里插入图片描述

Mac中安装homebrew

安装homebrew 执行下面安装语句

/usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”

1.错误1

首先出现如下报错:

curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 21 ms: Connection refused

解决方案:
参考彻底解决【“curl: (7) Failed to connect to raw.githubusercontent.com port 443: Connection refused”】错误

2.错误2

出现如下报错:

HEAD is now at f248a4f2904 skktools: update 1.3.4_2 bottle.
fatal: unable to access ‘https://github.com/Homebrew/brew/’: LibreSSL SSL_read: error:02FFF03C:system library:func(4095):Operation timed out, errno 60
fatal: unable to access ‘https://github.com/Homebrew/brew/’: LibreSSL SSL_read: error:02FFF03C:system library:func(4095):Operation timed out, errno 60
Error: Fetching /usr/local/Homebrew failed!
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!

解决方案:
执行下面语句

$ git config --global --unset http.proxy
$ git config --global --unset https.proxy
brew uptate

参考完美解决 fatal: unable to access ‘https://github.com/Homebrew/brew/‘

3.安装成功

==> Next steps:
- Run brew help to get started
- Further documentation:
https://docs.brew.sh在这里插入图片描述