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

MacOS下Flutter项目iOS模拟器构建失败问题求助

解决Flutter iOS模拟器Debug构建失败(Sandbox权限/文件写入错误)

问题复现

在MacOS上启动Flutter项目到iPhone Xr模拟器Debug模式时,出现以下构建错误:

Launching lib/main.dart on iPhone Xr in debug mode...
Updating project for Xcode compatibility.
Upgrading project.pbxproj
Upgrading Runner.xcscheme
Running pod install...
Running Xcode build...
Xcode build done. 1135.7s
Failed to build iOS app
Error (Xcode): Sandbox: rsync(15466) deny(1) file-write-create /Users/blesstembangacha/Downloads/incaresjobs/build/ios/Debug-iphonesimulator/Flutter.framework

Error (Xcode): Flutter failed to write to a file at "/Users/blesstembangacha/Downloads/incaresjobs/build/ios/Debug-iphonesimulator/.last_build_id".

Could not build the application for the simulator.
Error launching application on iPhone Xr.

其他Flutter项目可正常运行,说明问题出在当前项目的配置或权限上。

解决方案

1. 清理项目构建缓存

  • 执行Flutter清理命令:
    flutter clean
    
  • 进入iOS目录重新安装Pods:
    cd ios
    pod deintegrate
    pod install
    cd ..
    

2. 修复项目目录权限

  • 给项目目录赋予读写权限:
    sudo chmod -R 755 /Users/blesstembangacha/Downloads/incaresjobs
    
  • 若权限问题仍存在,将目录所有者改为当前用户:
    sudo chown -R $(whoami) /Users/blesstembangacha/Downloads/incaresjobs
    

3. 重置Xcode模拟器与缓存

  • 关闭所有模拟器,清理Xcode衍生数据:
    xcrun simctl erase all
    rm -rf ~/Library/Developer/Xcode/DerivedData
    
  • 重启Xcode,打开项目的iOS工程(ios/Runner.xcworkspace),尝试直接在Xcode中构建运行。

4. 检查版本兼容性

  • 验证Flutter与Xcode版本是否适配:
    flutter doctor
    
  • 若版本不兼容,升级Flutter到稳定版:
    flutter upgrade
    
    或根据Flutter官方适配说明调整Xcode版本。

5. 检查Xcode项目配置

  • 打开ios/Runner.xcworkspace,选中Runner target,进入Signing & Capabilities标签页:
    • 确认App Sandbox未被错误启用(Debug模式下模拟器无需开启该权限)。
    • 若已开启,暂时关闭后重新构建。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 02:12:13