Xcode编译报错求助:Multiple commands produce <execute-shell-script> 问题
Hey there, I’ve dealt with this exact frustrating issue before when working with multiple Xcode targets. Let’s walk through how to resolve it.
What’s causing this?
The error pops up because your main target PorjectName and extension target notificationServiceExt both have identical build script phases (like "Build Project Frameworks", "Build Assets Catalog", etc.). Xcode gets confused when two separate targets try to run identical scripts that produce the same output, so it throws this conflict error.
Step-by-step fixes:
First, identify duplicate scripts
Open your Xcode project, select the blue project icon, then switch betweenPorjectNameandnotificationServiceExtin the TARGETS list. Go to the Build Phases tab for each, and check for the script names mentioned in your error log—you’ll see they exist in both targets.Option 1: Remove redundant scripts
If the script is only needed for the main project (not the extension), simply delete the duplicate script phase from thenotificationServiceExttarget’s Build Phases. Right-click the script phase and select "Delete" to remove it.Option 2: Share a single external script file
If both targets need the script functionality, don’t duplicate the code. Create a new.shfile in your project (e.g.,BuildFrameworks.sh), paste the script content into it, then replace the inline script in both targets with a call to this external file. For example, use:"${PROJECT_DIR}/BuildFrameworks.sh"This way, Xcode recognizes the commands as separate (since they’re calling a file instead of having identical inline content), and the conflict goes away.
Option 3: Assign unique output paths
If you must keep separate inline scripts, expand each script phase (click the arrow in the top-right corner of the script block), then add a unique Output File path for each target. For example:- For
PorjectName:$(BUILT_PRODUCTS_DIR)/MainTarget_BuildFrameworks.output - For
notificationServiceExt:$(BUILT_PRODUCTS_DIR)/ExtTarget_BuildFrameworks.output
Xcode uses these output paths to distinguish between commands, so this should resolve the conflict.
- For
Clean and rebuild
After making changes, hitCmd+Shift+Kto clean the build folder, thenCmd+Bto rebuild your project. This ensures old build artifacts don’t interfere with the fix.
A quick heads-up
Sometimes these duplicate scripts get added automatically by tools like CocoaPods. Double-check your Podfile to make sure you’re not accidentally applying a post-install script to multiple targets when it only needs one.
内容的提问来源于stack exchange,提问作者Shiva_iOS

