Problem Description

When building an iOS application from a Flutter project, you may encounter the following error:

Error (Xcode): Flutter failed to write to a file at "~/[project_path]/build/ios/Release-iphoneos/.last_build_id"


Root Cause

This issue occurs due to cache and dependency version mismatches, particularly when working with Flutter projects that have been transferred between different systems or development environments. The error is typically triggered by Xcode's user script sandboxing feature, which prevents Flutter's build scripts from writing necessary cache files.


Solution

To resolve this issue, you need to disable Xcode's user script sandboxing for your project:

  1. Open Your Project in Xcode
    • Navigate to your Flutter project's ios folder
    • Open the .xcworkspace file (not the .xcodeproj file)
  2. Modify Build Settings
    • Select your project target in the navigator
    • Go to Build Settings
    • Search for ENABLE_USER_SCRIPT_SANDBOXING
    • Set the value to No
  3. Clean and Rebuild
    • Clean your project: Product → Clean Build Folder
    • Run your Flutter build command again: flutter build ios


Why This Works

The ENABLE_USER_SCRIPT_SANDBOXING setting controls whether Xcode restricts user scripts from accessing the file system. When enabled, it prevents Flutter's build scripts from creating necessary cache files like .last_build_id, which are required for proper incremental builds.

By setting this option to "No," you allow Flutter's build process to write the required files during compilation.


Interested in MacinCloud Managed Servers?

Visit the Managed Server Plan page to obtain a Managed server.


Do you require full root/admin privileges on a MacinCloud Server?

Find out more about MacinCloud Dedicated Server Plans
.