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
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:
- Open
ios/Pods/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh
- Find:shell
source="$(readlink "${source}")"
- 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:
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:
pod deintegrate
pod install
3. Update CocoaPods
Outdated CocoaPods versions cause script failures. Update to v1.12.1+:
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:
- Open your project in Xcode
- Navigate to: Runner → PROJECT (Runner) → Info → Deployment Target
- Set iOS Deployment Target to 12.0+
- For Pods project: Pods → PROJECT (Pods) → Info → Deployment Target
- Set all targets to 12.0+
5. Fix Firebase Script Errors
If migrating from CocoaPods to Swift Package Manager (SPM):
- 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"
- Enable "For install builds only" in script settings
6. Check Mac Storage Space
Insufficient disk space causes build failures:
- Go to Apple Menu → About This Mac → Storage
- Free up space if available storage is <10GB
- 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
:
# Change Line 7:
set -e → set +e
This prevents immediate exit on minor errors.
Reset Environment Files
Delete problematic config files:
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
Preventative Best Practices
Maintain updated dependencies:
bashflutter upgrade # For Flutter projects npx react-native upgrade # For React Native
Always use the latest tools:
bashnpm update -g # Update global packages pod repo update # Update CocoaPods specs
Clean builds when upgrading:
bashpod deintegrate rm -rf ios/Pods ios/Podfile.lock pod install
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 Context | Recommended Fix |
---|---|
Flutter-specific issues | Upgrade to Flutter 3.7.10+ |
Firebase Crashlytics errors | Fix script paths (Solution 5) |
"No such file or directory" in scripts | Check pod script paths (Solution 1) |
Archive/build failures only | Try CocoaPods update (Solution 3) |
Fresh project setup | Verify 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.