Xcode cannot find a build input file that a script should create
Build input file cannot be foundShort answer
Xcode's build system plans every step from declared inputs and outputs. This error means a file the build needs does not exist when that step runs. For a generated file the cause is one of three: the Run Script phase does not declare it as an output, the phase sits after the step that uses it, or the declared path differs from the real one.
Fix it fast
1Find out which cause you have
Read the exact path in the error, then check whether anything creates that file during the build. Print the Run Script phases of the target and which paths they declare.
xcodebuild -showBuildSettings -scheme MyApp | grep -E "DERIVED_FILE_DIR|SRCROOT" grep -n "outputPaths\|shellScript" MyApp.xcodeproj/project.pbxproj2Match what you see, then jump to its fix
- 1
The missing file is a generated one (code, plist, asset) and its path is not listed under Output Files of any Run Script phaseThe script creates the file but does not declare it as an outputFix - 2
The script phase is listed below the phase that fails, and the file is produced by that scriptThe Run Script phase is placed after the phase that needs its fileFix - 3
The output is declared, but the path in the error differs from it by a folder or a file nameThe declared output path is not where the script really writesFix
- 1
What does the error look like?
Build input file cannot be foundDid you forget to declare this file as an output of a script phase or custom build rule which produces it?
Cause 1 of 3
The script creates the file but does not declare it as an output
1Check
Open the target > Build Phases > the Run Script phase that writes the file, and look at the Output Files list. Apple notes that Xcode needs the input and output files of a script to run it and other concurrent tasks in the right order.
grep -n "outputPaths" MyApp.xcodeproj/project.pbxproj2Fix
Add the exact path of the generated file to Output Files in the Run Script phase, using build variables such as $(DERIVED_FILE_DIR) or $(SRCROOT) rather than a hard-coded absolute path.
# Output Files in the Run Script phase:
$(DERIVED_FILE_DIR)/Generated.swift3Verify
Build again. The build system now orders the script before the step that reads the file.
xcodebuild -scheme MyApp -destination 'generic/platform=iOS Simulator' buildConfirmed by developer.apple.com
Cause 2 of 3
The Run Script phase is placed after the phase that needs its file
1Check
In Build Phases, compare the position of the Run Script phase with Compile Sources. A script phase is a separate phase and runs at the point where you put it.
grep -n "buildPhases" -A 8 MyApp.xcodeproj/project.pbxproj2Fix
Drag the Run Script phase above the phase that consumes the file, and declare the file as its output so the order is also known to the build system.
# Build Phases: drag 'Run Script' above 'Compile Sources'3Verify
Clean the build folder (Product > Clean Build Folder) and build once; it must succeed on the first try.
xcodebuild -scheme MyApp -destination 'generic/platform=iOS Simulator' clean buildConfirmed by developer.apple.com
Cause 3 of 3
The declared output path is not where the script really writes
1Check
Print the output paths Xcode passes to the script. Xcode sets SCRIPT_OUTPUT_FILE_COUNT and SCRIPT_OUTPUT_FILE_0, SCRIPT_OUTPUT_FILE_1 and so on for each declared output.
# temporarily add to the top of the script:
echo "outputs: ${SCRIPT_OUTPUT_FILE_COUNT} first: ${SCRIPT_OUTPUT_FILE_0}"2Fix
Write the file to the declared path by using the variable in the script itself, so the two can never drift apart.
python3 "${SRCROOT}/Scripts/generate.py" > "${SCRIPT_OUTPUT_FILE_0}"3Verify
Build and confirm the file exists at the declared path.
ls -l "$(xcodebuild -scheme MyApp -showBuildSettings | awk '/ DERIVED_FILE_DIR /{print $3}')"Confirmed by developer.apple.com
How do I stop it coming back?
- Declare every file a script generates as an output of that script, and every file it reads as an input.
- Build with a clean build folder before merging a change to a Run Script phase.
- Use the SCRIPT_OUTPUT_FILE_n variables in scripts instead of repeating paths.
- Keep generated code under DERIVED_FILE_DIR instead of the source tree.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Mobile apps
Xcode warns that a Run Script phase runs on every build
Run script build phase 'Module' will be run during every build because it does not specify any outputs.
Xcode runs a Run Script phase on every build when it has no input files, no output files, changed inputs or missing outputs.
3 causes, each with a fixMobile apps
UserDefaults logs 'Failed to read values in CFPrefsPlistSource' for an app group
Settings saved by the app are not visible to its extension, widget or sibling app that share the group
This log comes from the preferences system when UserDefaults is opened for an app group's suite.
3 causes, each with a fixMobile apps
iOS app crashes: Google Maps SDK must be initialized via provideAPIKey
Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey:...] prior to use
The Maps SDK throws this when a Maps object is created before GMSServices.provideAPIKey has run.
3 causes, each with a fixMobile apps
UIKit app crashes because it cannot find the storyboard
Could not find a storyboard named 'Main' in bundle NSBundle
UIStoryboard throws this exception when no storyboard file with that name exists in the bundle it searches.
3 causes, each with a fixMobile apps
Firebase on iOS asks for the FCM token before APNs has given one
Be sure to re-retrieve the FCM token once the APNS device token is set.
The Firebase Messaging SDK needs the APNs device token from iOS before it hands out an FCM token.
3 causes, each with a fixMobile apps
A test push from the Firebase console never shows up on the iPhone
didReceiveRegistrationToken prints a token, yet no notification arrives
When a console message is accepted but the iPhone stays silent, the break is between Firebase and APNs or inside the app.
4 causes, each with a fix