M1芯片模拟器运行项目报错:添加排除架构后仍出现Command PhaseScriptExecution failed with a nonzero exit code错误
Hey there, I’ve run into this exact headache a few times with M1 Macs and Xcode simulator builds—let’s walk through some practical fixes to get your project running again:
Launch Xcode via Rosetta
A lot of older build scripts still aren’t optimized for arm64. Right-click the Xcode app in your Applications folder, select Get Info, check "Open using Rosetta", then restart Xcode and try building again. This forces Xcode to run in x86_64 mode, which often resolves script compatibility issues.Verify and fix script permissions
The error might stem from a build script lacking execute permissions. To fix this:- Locate the problematic script from the error log (it’ll show the full path, e.g.,
Pods/Target Support Files/Pods-YourApp/Pods-YourApp-frameworks.sh). - Open Terminal, run
chmod +x /full/path/to/your/script.shto grant execute access. - Rebuild your project.
- Locate the problematic script from the error log (it’ll show the full path, e.g.,
Clean project and reset Derived Data
Corrupted cache is a super common culprit here:- Press
Cmd + Shift + Kin Xcode to clean the project. - Go to Xcode > Settings > Locations, click the arrow next to Derived Data to open the folder. Delete the folder for your project, then restart Xcode and rebuild.
- Press
Update your CocoaPods configuration (if using Pods)
If you’re using CocoaPods, make sure your Podfile has M1-compatible settings. Add this block at the end of your Podfile:post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64' end end endThen run
pod installin Terminal, and rebuild your project.Reset Xcode’s global build cache
Sometimes the global Xcode cache gets messed up. Run this command in Terminal to clear it:rm -rf ~/Library/Caches/com.apple.dt.XcodeRestart Xcode after running this, then try building again.
If none of these work, grab the full error log from the Report Navigator (the last tab in Xcode’s left sidebar) and share the specific script that’s failing—this will help narrow down the exact issue.
内容的提问来源于stack exchange,提问作者NoName555

