环境:
[✓] Flutter (Channel stable, 3.7.9, on macOS 13.2 22D49 darwin-x64, locale
zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.3)
[✓] VS Code (version 1.76.2)
Homebrew 4.0.3-99-g68859ae
Flutter中文网
一:Flutter环境配置
1:Flutter SDK下载
这里我下载的是flutter_macos_3.7.7-stable解压到盘目录/Users/yaodong/flutter
2:环境配置
首先查看自己所使用的shell https://support.apple.com/zh-cn/HT208050
如果是 bash
环境变量配置:
vim ~/.bash_profile
添加环境变量:
export PATH="/Users/yaodong/flutter/bin:$PATH"
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_UUL=https://storage.flutter-io.cn
保存后刷新:
source ~/.bash_profile
如果是 zsh
环境变量配置:
vim .zshrc
添加环境变量:
export PATH="/Users/yaodong/flutter/bin:$PATH"
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_UUL=https://storage.flutter-io.cn
保存后刷新:
source .zshrc
注意:终端编辑命令i编辑,esc输入命令,:wq保存并退出
3:运行 flutter doctor
打开 终端,输入flutter doctor
- 出现:You have not agreed to the Xcode license agreements
Failed to find the latest git commit date: VersionCheckError: Command exited
with code 69: git -c log.showSignature=false log HEAD -n 1 --pretty=format:%ad
--date=iso
Standard out:
Standard error:
You have not agreed to the Xcode license agreements, please run 'sudo xcodebuild
-license' from within a Terminal window to review and agree to the Xcode license
agreements.
# 按要求执行
sudo xcodebuild -license
# 又出现
You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.
其实就是下面这个,xcode重装的,还没打开过
-
出现:cmdline-tools component is missing
在Android studio的SDK Manager中SDK Tools选择安装
出现:Android证书问题
//出现 Android证书问题
! Some Android licenses not accepted. To resolve this, run: flutter doctor -- android-licenses
//执行
flutter doctor --android-licenses 一直Yes即可
- 出现 CocoaPods not installed
确保安装了HomeBrew,参考Homebrew国内如何自动安装
brew install cocoapods
- 出现 ios-deploy 未安装
//这个是终端安装和调试iPhone应用的是第三方开源库
[!] iOS tools - develop for iOS devices
✗ ios-deploy out of date (1.9.4 is required). To upgrade with Brew:
brew upgrade ios-deploy
// 我这里使用node安装的
- 出现:开发环境配置问题(下面会讲到)
[!]Android Studio (version 3.4)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
//如果安装了 IntelliJ IDEA 也会检测到
[!] IntelliJ IDEA Ultimate Edition (version 2017.2.5)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
- ios-deploy not installed 按照提示执行brew install ios-deploy
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
[!] iOS tools - develop for iOS devices
✗ ios-deploy not installed. To install:
brew install ios-deploy
[✓] Android Studio (version 3.4)
[!] IntelliJ IDEA Ultimate Edition (version 2017.2.5)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available
二:Flutter IDE 配置
1:Android Studio或Viual Studio Code下载
2:Android Studio 在File>Setting>Plugins>MarketPlace中搜索Flutter,安装搜索结果第一条,成功后按提示重启
3:Android Studio File>Setting>Languages>Flutter中设置Flutter路径,/Users/yaodong/flutter
4: Android Studio File>Setting>Languages>Dart 中设置Dart SDK,/Users/yaodong/flutter/bin/cache/dart-sdk(第一步已直接设置好,检查即可)
三:最终运行flutter doctor
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 11.0)
[✓] iOS tools - develop for iOS devices
[✓] Android Studio (version 3.4)
[!] IntelliJ IDEA Ultimate Edition (version 2017.2.5)
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available
1:因为我安装了IntelliJ IDEA,所以提示我需要配置flutter环境变量
2:未连接真机或者未生成模拟器,会提示No devices available
四:工程运行
1:File>New>New Flutter Project
2:运行(连接真机或新建模拟器即可)
Launching lib/main.dart on YDPhone in debug mode...
Signing iOS app for device deployment using developer identity: "iPhone Developer: xxxxx"
Running Xcode build...
Xcode build done. 17.0s
Installing and launching...
Syncing files to device YDPhone...