You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级macOS Sonoma后Flutter热重载/热重启失效求助

macOS Sonoma升级后Flutter热重载/热重启失败的解决方案

问题描述

升级macOS至Sonoma后,Flutter开发环境无法正常执行热重载与热重启操作。在VS Code中触发操作时,持续抛出文件创建失败的错误:

热重载错误信息:

Failed to Hot Reload: DebugAdapterException: Flutter failed to create file at "/Users/hotdog/Library/Containers/com.example.firstApp/Data/tmp/first_app2fr7NB/first_app/main.dart.incremental.dill".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.

热重启错误信息:

Failed to Hot Restart: DebugAdapterException: Flutter failed to create file at "/Users/hotdog/Library/Containers/com.example.firstApp/Data/tmp/first_appnSNkrN/first_app/main.dart.dill".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.

执行flutter doctor检测,除未使用的Android工具链外,其余环境均正常:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.7, on macOS 14.0 23A344 darwin-x64, locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ✗ 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 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.84.2)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 1 category.

检查/Users/hotdog/Library/Containers/目录,发现报错中提及的com.example.firstApp文件夹并不存在。

可能原因

macOS Sonoma更新后,系统对~/Library/Containers目录的权限策略发生调整,导致Flutter无法自动创建对应的应用容器目录及临时文件;同时旧版本Flutter(如3.13.x)对新系统的权限适配存在兼容问题。

解决方法

以下是经开发者验证有效的解决步骤,可逐一尝试:

  • 手动创建目标容器目录并赋予权限
    打开终端执行以下命令:

    # 创建完整目录结构
    mkdir -p /Users/hotdog/Library/Containers/com.example.firstApp/Data/tmp
    # 赋予当前用户读写权限
    chown -R $USER:$USER /Users/hotdog/Library/Containers/com.example.firstApp
    

    完成后重启VS Code,再次尝试热重载/热重启。

  • 更新Flutter到最新稳定版
    终端执行升级命令:

    flutter upgrade
    

    升级完成后执行flutter doctor确认环境正常,再重启开发工具重试。

  • 重置项目调试环境

    1. 关闭VS Code,删除项目根目录下的.dart_tool和build文件夹;
    2. 重新打开项目,依次执行:
      flutter clean
      flutter pub get
      
    3. 重新启动调试会话测试热重载功能。
  • 检查系统隐私权限

    1. 打开「系统设置」→「隐私与安全性」→「文件与文件夹」;
    2. 找到VS Code和终端应用,确保它们拥有「Library」等相关目录的访问权限;
    3. 勾选权限后重启对应应用重试。
  • 切换Flutter通道测试(可选)
    如果稳定版升级后仍有问题,可尝试切换到beta通道:

    flutter channel beta
    flutter upgrade
    

    问题解决后可切回稳定版:

    flutter channel stable
    flutter upgrade
    

内容的提问来源于stack exchange,提问作者John

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 05:03:20