Errors building Xcode Project after adding in Run Script fatal error: lipo: input file

SamoanProgrammer picture SamoanProgrammer · Feb 6, 2016 · Viewed 9.2k times · Source

I had the following errors when attempting to upload my app to the App Store ERROR ITMS-90087, ERROR ITMS-90209, & ERROR ITMS-90125 as outlined in this Question Submit to App Store issues: Unsupported Architecture x86 and used the script shown below to try and fix the problem:

APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

EXTRACTED_ARCHS=()

for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done

echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"

echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

done

Now I'm getting a lot of errors trying to compile my code in Xcode.

Executable is /Users/[Username]/Library/Developer/Xcode/DerivedData/[AppName]-egnqksafjoylrcaxerbjrknmxdgl/Build/Products/Debug-iphoneos/[AppName].app/Frameworks/Bolts.framework/Bolts
Extracting arm64 from Bolts

fatal error: lipo: input file (/Users/[Username]/Library/Developer/Xcode/DerivedData/[AppName]-egnqksafjoylrcaxerbjrknmxdgl/Build/Products/Debug-iphoneos/[AppName].app/Frameworks/Bolts.framework/Bolts) must be a fat file when the -extract option is specified

Merging extracted architectures: arm64
fatal error: lipo: can't open input file: /Users/[Username]/Library/Developer/Xcode/DerivedData/[AppName]-egnqksafjoylrcaxerbjrknmxdgl/Build/Products/Debug-iphoneos/[AppName].app/Frameworks/Bolts.framework/Bolts-arm64 (No such file or directory)

rm: /Users/[Username]/Library/Developer/Xcode/DerivedData/[AppName]-egnqksafjoylrcaxerbjrknmxdgl/Build/Products/Debug-iphoneos/[AppName].app/Frameworks/Bolts.framework/Bolts-arm64: No such file or directory

Replacing original executable with thinned version
mv: rename /Users/[Username]/Library/Developer/Xcode/DerivedData/[AppName]-egnqksafjoylrcaxerbjrknmxdgl/Build/Products/Debug-iphoneos/[AppName].app/Frameworks/Bolts.framework/Bolts-merged to /Users/[Username]/Library/Developer/Xcode/DerivedData/[AppName]-egnqksafjoylrcaxerbjrknmxdgl/Build/Products/Debug-iphoneos/[AppName].app/Frameworks/Bolts.framework/Bolts: No such file or directory

Any ideas how to fix?

Answer

Jereme picture Jereme · Jun 28, 2017

I've edited the script to try and identify if the framework is FAT. If it is, then it skips it.

#!/usr/bin/env bash

APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
    FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
    FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"

    if [ ! -f "${FRAMEWORK_EXECUTABLE_PATH}" ]; then
        continue
    fi

    if xcrun lipo -info "${FRAMEWORK_EXECUTABLE_PATH}" | grep --silent "Non-fat"; then
        echo "Framework non-fat, skipping: $FRAMEWORK_EXECUTABLE_NAME"
        continue
    fi

    echo "Thinning framework $FRAMEWORK_EXECUTABLE_NAME"

    EXTRACTED_ARCHS=()

    for ARCH in $ARCHS
    do
        echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
        xcrun lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
        EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
    done

    echo "Merging extracted architectures: ${ARCHS}"
    xcrun lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
    rm "${EXTRACTED_ARCHS[@]}"

    echo "Replacing original executable with thinned version"
    rm "$FRAMEWORK_EXECUTABLE_PATH"
    mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done