开发环境
Mac M1
Xcode
Android Studio
VSCode
配置Flutter开发环境
按照https://flutterchina.club/步骤操作即可。
如果本地没有 iOS 和 Android 开发环境,建议先安装 Xcode 和 Android Studio,我本地 iOS 和 Android 的开发环境都是没问题的,Visual Studio Code 也没啥问题,直接按照网上提供的步骤进行环境配置。
以下是我在 M1 上搭建Flutter开发环境遇到的问题以及解决方法
➜ Documents flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.0, on macOS 12.2 21D49 darwin-arm (Rosetta), locale zh-Hans-CN)
[!] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
✗ 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 (Xcode 13.2.1)
[✓] Chrome - develop for the web
[!] Android Studio
✗ Unable to find bundled Java version.
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.67.1)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 2 categories.
cmdline-tools component is missing
和 Android license status unknown
打开Android Studio, Android Studio -> Preferences -> Appearance & Behavior -> System Settings -> Android SDK 下,勾选 Andriod SDK Command-line Tools(latest),然后Apply。
如下图:
Unable to find bundled Java version
原因时我本地安装了Android Studio 和 Android Studio Preview,我把 Android Studio Preview 卸载了重新 flutter doctor,问题解决了。
[!] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
终端执行 flutter doctor --android-licenses,一路 y 即可。
✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues. ✗ HandshakeException: Connection terminated during handshake
这个错误我没管…
最后执行 flutter doctor 效果如下:
➜ Documents flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.0, on macOS 12.2 21D49 darwin-arm (Rosetta), locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.67.1)
[✓] Connected device (2 available)
HTTP Host availability check is taking a long time...[☠] HTTP Host Availability (the doctor check crashed)
✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know
about this issue at https://github.com/flutter/flutter/issues.
✗ HandshakeException: Connection terminated during handshake
! Doctor found issues in 1 category.
之后按照官网指导,继续做就可以了。
配置编辑器
VSCode 安装插件 Flutter 即可。