Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Xcode says a script phase failed, but not which one or why

ErrorCommand PhaseScriptExecution failed with a nonzero exit code

Short answer

This line only reports that one Run Script build phase exited with an error. The phase name after PhaseScriptExecution says which script, and the lines printed just above it say why. In Flutter and CocoaPods projects the usual culprits are an out-of-sync Podfile.lock, user script sandboxing, a stale Flutter SDK path, or a Dart build error.

  • Applies to Xcode 26, Flutter 3.44 stable, CocoaPods 1.17, macOS 26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Build from the terminal so the whole script output is kept, and print the lines just before the failure. The name in the PhaseScriptExecution line (for example Run Script, Thin Binary or [CP] Check Pods Manifest.lock) tells you which phase failed; the lines above it are that script's own message.

    flutter build ios --no-codesign -v 2>&1 | grep -n -B25 "PhaseScriptExecution failed"
  2. 2Match what you see, then jump to its fix

    1. 1error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.[CP] Check Pods Manifest.lock: the Pods folder does not match Podfile.lockFix
    2. 2Sandbox: … deny(1) file-read-data or file-write-create on a path in your project or DerivedData, printed by a Run Script or [CP] Embed Pods Frameworks phaseUser script sandboxing blocks a script from reading or writing a fileFix
    3. 3…/packages/flutter_tools/bin/xcode_backend.sh: No such file or directory, often right after moving or reinstalling the Flutter SDKRun Script or Thin Binary cannot find Flutter: FLUTTER_ROOT is staleFix
    4. 4Failed to package …, or a Dart error, missing asset or Flutter tool message printed just above the PhaseScriptExecution line for the Run Script phaseThe Flutter build inside the Run Script phase failedFix

What does the error look like?

  • Command PhaseScriptExecution failed with a nonzero exit code
  • error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
  • Sandbox: rsync(…) deny(1) file-read-data …/Pods/Target Support Files/…
  • /bin/sh: …/packages/flutter_tools/bin/xcode_backend.sh: No such file or directory

Cause 1 of 4

[CP] Check Pods Manifest.lock: the Pods folder does not match Podfile.lock

1Check

CocoaPods adds a script phase that compares Podfile.lock with Pods/Manifest.lock and stops the build when they differ. That happens after a pull that changed Podfile.lock, a plugin change, or a Pods folder made by another CocoaPods version. Run the same comparison by hand.

diff ios/Podfile.lock ios/Pods/Manifest.lock && echo same

2Fix

Install the pods again from the ios folder so Pods/Manifest.lock is rewritten. For a Flutter app, run pub get first so the plugin list is current.

flutter pub get
cd ios && pod install

3Verify

The two files are identical and the build gets past the phase.

diff ios/Podfile.lock ios/Pods/Manifest.lock && echo same
flutter build ios --no-codesign

Confirmed by github.com

Did this fix it?

Cause 2 of 4

User script sandboxing blocks a script from reading or writing a file

1Check

Since Xcode 14 the ENABLE_USER_SCRIPT_SANDBOXING build setting can be turned on for shell script phases. When it is on, a script may not touch files inside the project folder or Derived Data unless they are listed as inputs or outputs, and the build fails with a sandbox violation. Flutter's own project template sets it to NO. Look at the value your target resolves to.

xcodebuild -workspace ios/Runner.xcworkspace -scheme Runner -showBuildSettings \
  | grep ENABLE_USER_SCRIPT_SANDBOXING

2Fix

For a Flutter app, set User Script Sandboxing to No on the Runner target (Build Settings > Build Options), as the Flutter template does, and do the same on any extra app targets. For scripts you own, the stricter fix is to list every file they read as an input file and every file they write as an output file in the phase.

# in ios/Runner.xcodeproj/project.pbxproj the setting reads
ENABLE_USER_SCRIPT_SANDBOXING = NO;

3Verify

The resolved setting prints NO and the same build passes.

xcodebuild -workspace ios/Runner.xcworkspace -scheme Runner -showBuildSettings \
  | grep ENABLE_USER_SCRIPT_SANDBOXING

Confirmed by developer.apple.com

Did this fix it?

Cause 3 of 4

Run Script or Thin Binary cannot find Flutter: FLUTTER_ROOT is stale

1Check

Flutter's Run Script and Thin Binary phases run xcode_backend.sh from the folder named by FLUTTER_ROOT. Flutter writes that value into ios/Flutter/Generated.xcconfig when it prepares the iOS project, so the file keeps the old path until Flutter regenerates it.

grep FLUTTER_ROOT ios/Flutter/Generated.xcconfig
flutter --version --machine | grep flutterRoot

2Fix

Run pub get from the project root so Flutter rewrites Generated.xcconfig with the current SDK folder, then build again.

flutter clean
flutter pub get

3Verify

FLUTTER_ROOT now matches the SDK you run, and the script file exists.

grep FLUTTER_ROOT ios/Flutter/Generated.xcconfig
ls "$(flutter --version --machine | python3 -c 'import json,sys;print(json.load(sys.stdin)["flutterRoot"])')/packages/flutter_tools/bin/xcode_backend.sh"

Confirmed by github.com

Did this fix it?

Cause 4 of 4

The Flutter build inside the Run Script phase failed

1Check

The Run Script phase calls flutter assemble through xcode_backend.sh. If that command exits with an error the script prints Failed to package and exits, and Xcode reduces all of it to the PhaseScriptExecution line. The real message is the Flutter tool output above.

flutter analyze
flutter build ios --no-codesign -v 2>&1 | grep -n -B15 "Failed to package"

2Fix

Fix the first Dart, asset or dependency error shown, then build again. The same error appears in plain flutter build, so you can debug there instead of inside Xcode.

flutter pub get
flutter build ios --no-codesign

3Verify

flutter build ios finishes and Xcode builds the same project.

flutter build ios --no-codesign

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Commit Podfile.lock and run pod install after every pull that changes it.
  • After moving or upgrading the Flutter SDK, run flutter clean and flutter pub get before opening Xcode.
  • Keep User Script Sandboxing at the value Flutter's template uses, and declare input and output files for scripts you add.
  • Build with flutter build ios in CI so the full script output is in the log, not only the Xcode summary line.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.