Skip to content

Xcode PhaseScriptExecution Error Fix ​

Problem Statement ​

After updating to Xcode 14 or newer versions, developers frequently encounter the error:

Command PhaseScriptExecution failed with a nonzero exit code

This error occurs during the build process when a shell script phase (like CocoaPods integration or framework linking) fails. Common triggers include:

  • Xcode version updates (especially 14+)
  • Flutter or React Native projects
  • CocoaPods dependency management
  • Firebase integration scripts
  • Insufficient disk space on macOS

Xcode Error Screenshot

The generic error message makes diagnosis challenging, but the solutions below cover the most effective resolutions.

Solutions ​

1. Fix CocoaPods Framework Script (Most Common) ​

For Cordova, React Native, or Flutter projects, modify your Pods-Runner-frameworks.sh file:

  1. Open ios/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh
  2. Find:
    shell
    source="$(readlink "${source}")"
  3. Replace with:
    shell
    source="$(readlink -f "${source}")"

The -f flag resolves symbolic links correctly. After making this change, rebuild your project.

WARNING

This file is regenerated during pod install. Add this fix to a custom post-install script to make it persistent.

2. Set iOS Deployment Target in Podfile ​

Add this to your ios/Podfile's post_install block:

ruby
post_install do |installer|
  installer.pods_project.targets.each do |target|
    # Existing Flutter settings (keep if present)
    flutter_additional_ios_build_settings(target)
  end
  
  # Add this deployment target configuration:
  installer.generated_projects.each do |project|
    project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
      end
    end
  end
end

After updating, reconnect pods:

bash
pod deintegrate
pod install

3. Update CocoaPods ​

Outdated CocoaPods versions cause script failures. Update to v1.12.1+:

bash
sudo gem install cocoapods
pod repo update
pod install

TIP

Always close Xcode before running terminal Pod commands.

4. Adjust Build Configuration Settings ​

For Flutter projects:

  1. Open your project in Xcode
  2. Navigate to: Runner → PROJECT (Runner) → Info → Deployment Target
  3. Set iOS Deployment Target to 12.0+
  4. For Pods project: Pods → PROJECT (Pods) → Info → Deployment Target
  5. Set all targets to 12.0+

Deployment Target Settings

5. Fix Firebase Script Errors ​

If migrating from CocoaPods to Swift Package Manager (SPM):

  1. Update the Firebase script path in Build Phases > Run Script:
    bash
    # Change this:
    "${PODS_ROOT}/FirebaseCrashlytics/run"
    
    # To this:
    "${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run"
  2. Enable "For install builds only" in script settings

6. Check Mac Storage Space ​

Insufficient disk space causes build failures:

  1. Go to Apple Menu → About This Mac → Storage
  2. Free up space if available storage is <10GB
  3. Delete unnecessary Xcode DerivedData:
    bash
    rm -rf ~/Library/Developer/Xcode/DerivedData/*

7. Additional Troubleshooting Steps ​

Fix React Native find-node.sh ​

Edit node_modules/react-native/scripts/find-node.sh:

bash
# Change Line 7:
set -e   →   set +e

This prevents immediate exit on minor errors.

Reset Environment Files ​

Delete problematic config files:

bash
rm -rf .xcode.env.local

Fix Configuration Mappings ​

In Xcode → Runner → Configurations:

  • Map Pods-Runner.debug → Debug
  • Map Pods-Runner.release → Release
  • Map Pods-Runner.profile → Release

Configuration Mapping Fix

Preventative Best Practices ​

  1. Maintain updated dependencies:

    bash
    flutter upgrade        # For Flutter projects
    npx react-native upgrade # For React Native
  2. Always use the latest tools:

    bash
    npm update -g          # Update global packages
    pod repo update        # Update CocoaPods specs
  3. Clean builds when upgrading:

    bash
    pod deintegrate
    rm -rf ios/Pods ios/Podfile.lock
    pod install
  4. Enable Rosetta for Intel Macs:

    • Right-click Xcode → Get Info
    • Check "Open using Rosetta"

DANGER

For production builds, test solutions in development environments before deployment. Some workarounds (like find-node.sh edits) should be temporary fixes until libraries release official patches.

When Solutions Don't Apply ​

Error ContextRecommended Fix
Flutter-specific issuesUpgrade to Flutter 3.7.10+
Firebase Crashlytics errorsFix script paths (Solution 5)
"No such file or directory" in scriptsCheck pod script paths (Solution 1)
Archive/build failures onlyTry CocoaPods update (Solution 3)
Fresh project setupVerify deployment targets (Solution 4)

Always check the build phase error logs in Xcode to identify the exact script causing failure – this provides the best clue for targeted fixes.

INFO

These solutions apply to Xcode 14 through Xcode 15+. They are verified for projects using CocoaPods, Flutter, React Native, Cordova, and native iOS development.