Mac上Flutter开发环境搭建

  1. 安装Dart SDK
brew tap dart-lang/dart
brew install dart
  1. 配置VSCode
    安装Dart、Code Runner插件
  2. 下载Flutter SDK
  3. 解压Flutter SDK压缩包到目标路径
  4. 配置flutter的PATH环境变量
    比如我的,在.zshrc文件中增加下面一行:
export PATH="$PATH:/Users/wlm/workspace/development/flutter/bin"

通过下面两个命令验证PATH环境变量是否添加成功:

echo $PATH
which flutter
  1. 通过命令行创建一个Flutter应用
flutter create my_app
  1. 启动应用
cd my_app
flutter run

报错:

Multiple devices found:
macOS (desktop) • macos  • darwin-x64     • macOS 12.1 21C52 darwin-x64
Chrome (web)    • chrome • web-javascript • Google Chrome 108.0.5359.124
[1]: macOS (macos)
[2]: Chrome (chrome)
Please choose one (To quit, press "q/Q"): 1
Launching lib/main.dart on macOS in debug mode...
ProcessException: Process exited abnormally:
xcrun: error: unable to find utility "xcodebuild", not a developer tool or in PATH
  Command: xcrun xcodebuild -list -project Runner.xcodeproj

这是因为Mac电脑没有Xcode,安装后再次运行,出现下面的提示:

Building flutter tool...
Multiple devices found:
macOS (desktop) • macos  • darwin-x64     • macOS 12.1 21C52 darwin-x64
Chrome (web)    • chrome • web-javascript • Google Chrome 108.0.5359.124
[1]: macOS (macos)
[2]: Chrome (chrome)
Please choose one (To quit, press "q/Q"): 1
Running "flutter pub get" in my_app...                             505ms
Launching lib/main.dart on macOS in debug mode...
Building macOS application...
Syncing files to device macOS...                                   152ms

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

💪 Running with sound null safety 💪

An Observatory debugger and profiler on macOS is available at: http://127.0.0.1:53719/92xA0GO6XBc=/
The Flutter DevTools debugger and profiler on macOS is available at:
http://127.0.0.1:9101?uri=http://127.0.0.1:53719/92xA0GO6XBc=/
Lost connection to device.

界面运行起来如下:
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值