官方文档地址:https://docs.flutter.dev/get-started/install/macos
按官方文档 Step By Step安装环境,flutter doctor 诊断报错如下:
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.4, on macOS 12.2 21D49 darwin-arm, locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See [https://developer.android.com/studio/command-line](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](https://flutter.dev/docs/get-started/install/macos#android-setup) for more details.
[✗] 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/](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.
To re-install see [https://guides.cocoapods.org/using/getting-started.html#installation](https://guides.cocoapods.org/using/getting-started.html#installation) for instructions.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] Android Studio (version 2020.3)
[✓] Connected device (1 available)
[!] HTTP Host Availability
✗ HTTP host [https://pub.flutter-io.cn](https://pub.flutter-io.cn) is not reachable. Reason: An error occurred while checking the HTTP host: HttpException: Proxy failed to establish tunnel (403 Forbidden), uri = //pub.[flutter-io.cn:443](http://flutter-io.cn:443)
✗ HTTP host [https://storage.flutter-io.cn](https://storage.flutter-io.cn) is not reachable. Reason: An error occurred while checking the HTTP host: HttpException: Proxy failed to establish tunnel (403 Forbidden), uri = //storage.[flutter-io.cn:443](http://flutter-io.cn:443)
解决方案:
- 打开Android Studio 安装最新SDK
- 执行 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.
解决方案: double check 文档,原来要求Android SDK,Command-line Tools, Build-Tools 都要安装最新版本
安装最新Command-line Tools like this:
继续执行flutter doctor 进行环境诊断,报错如下:
解决方法:
- 找到flutter sdk的文件目录,打开flutter/packages/flutter_tools/lib/src/http_host_validator.dart
- 将https://maven.google.com/ 修改为https://dl.google.com/dl/android/maven2/
- 关闭cmd命令窗口,重新打开cmd窗口
- 去到flutter/bin目录,删除cache文件夹
- 在cmd命令窗口重新运行flutter doctor,问题解决