Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Xcode cannot find a build input file that a script should create

ErrorBuild input file cannot be found

Short 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.

  • Applies to Xcode 26, Swift 6, macOS 26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.pbxproj
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The 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. 3The 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

What does the error look like?

  • Build input file cannot be found
  • Did 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.pbxproj

2Fix

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.swift

3Verify

Build again. The build system now orders the script before the step that reads the file.

xcodebuild -scheme MyApp -destination 'generic/platform=iOS Simulator' build

Confirmed by developer.apple.com

Did this fix it?

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.pbxproj

2Fix

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 build

Confirmed by developer.apple.com

Did this fix it?

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

Did this fix it?

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.