Xcode构建iOS项目报错:PhaseScriptExecution与CompileSwiftSources执行失败求助
Hey there, let’s dig into this build failure you’re hitting on your M1 Pro MacBook Pro. I’ve gone through all the details you shared, and here are some targeted fixes worth trying next:
Double-check Compilation Mode across Project and Target levels
You mentioned Compilation Mode was already set toIncremental, but sometimes project-level settings get overridden by target-specific ones. Head to your project in Xcode:- Select your main project (top level in the navigator) and check
Build Settings > Swift Compiler - Code Generation > Compilation Mode - Then select each individual target you’re building and verify the same setting matches. Ensure neither is set to
Whole Module—this is the root cause of the "Incremental compilation has been disabled" warning.
- Select your main project (top level in the navigator) and check
Fix arm64 Architecture Exclusions (Simulator vs Device)
For M1 Macs, simulator builds need special handling for arm64, but physical devices require it. Here’s the correct setup:- Go to your target’s
Build Settings > Architectures > Excluded Architectures - Click the "+" button, add
arm64only for the iOS Simulator platform (use the dropdown to select the platform, don’t set it globally) - Set
Build Active Architecture OnlytoYesfor theDebugconfiguration. For physical device builds, don’t exclude arm64 at all.
- Go to your target’s
Wipe Xcode Caches and Derived Data
Corrupted caches are a common culprit for weird build failures. Let’s do a full reset:- Quit Xcode completely
- Open Terminal and run these commands:
rm -rf ~/Library/Developer/Xcode/DerivedData rm -rf ~/Library/Caches/com.apple.dt.Xcode - Reopen Xcode, hit
Cmd+Shift+Kto clean the project, then try building again.
Debug the PhaseScriptExecution Failure
TheCommand PhaseScriptExecution failederror usually points to a custom build script (like CocoaPods, SwiftLint, or Node.js-based tools) failing. Here’s how to fix it:Expand the full error log by clicking the red failure message—this will show you exactly which script is breaking.
- If it’s a CocoaPods script: Run
pod deintegratethenpod installin your project directory to reset pods. - If it’s a Node/npm-related script: Delete your
node_modulesfolder and runnpm installagain. Ensure your Node packages are updated to M1-compatible versions.
- If it’s a CocoaPods script: Run
Verify Swift Package Dependencies
If your project uses Swift Packages, outdated or incompatible dependencies can break compilation:- Go to
File > Packages > Resolve Package Versionsto refresh dependencies - Check if any packages have known M1/Xcode compatibility issues—update them to the latest version, or switch to a fork that fixes the problem if available.
- Go to
Test with a Fresh Project
If none of the above work, create a blank iOS project in Xcode and try building it to simulator/device. If this works, the issue is specific to your project’s configuration. Gradually migrate your files, settings, and dependencies to the new project to pinpoint what’s causing the failure.
内容的提问来源于stack exchange,提问作者user18989112

