Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check and Remove Unsupported Architecture [x86_64, i386] in IPA / Archive

Problem:

While submitting the app to the App Store the following error is reported:

Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]

Questions:

  1. How can the above error be resolved ?

  2. How can I check the architectures used by the archive or IPA ?

  3. How can I ensure that the Release archive doesn't include x86_64 and i386 (simulator architectures).

    • Is it only possible through script or is there is a setting in Build Settings or else where ?
like image 277
user1046037 Avatar asked Mar 07 '17 06:03

user1046037


4 Answers

Apple has started complaining if app contains simulator architectures during distribution.

How can the above error be resolved ?

Solution :

Add below code in run script of Project target, this remove the simulator architecture (x86_64 and i386) from your app on building process:

Shell :

/bin/sh

Code :

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

Solution :

There one more solution, if you wish to do it only once. But be careful though as after doing following steps, you will not be able to run app on simulator. Do it just before deploying the app on Testflight/App-store.

Go inside the your ProjectFramework.framework folder of your project from terminal. Run following commands:

lipo -remove i386 ProjectFramework_SDK -o ProjectFramework_SDK 
lipo -remove x86_64 ProjectFramework_SDK -o ProjectFramework_SDK

Check the architectures from framework?

$ lipo -info PathToProject/ProjectName.framework/ProjectName

Output will be : → Architectures in the fat file: ProjectName are: i386 x86_64 armv7 arm64

Ref. doc: http://ikennd.ac/blog/2015/02/stripping-unwanted-architectures-from-dynamic-libraries-in-xcode/

like image 173
nikdange_me Avatar answered Nov 18 '22 15:11

nikdange_me


For custom created Dynamic Framework

  1. Open Terminal

  2. Open your project drag path of respective framework to Terminal

    For example, cd /Users/mahipal/Desktop/masterTest/Alamofire.framework

  3. Set your Framework name in below command and run

    lipo -remove i386 Alamofire -o Alamofire && lipo -remove x86_64 Alamofire -o Alamofire

like image 43
MAhipal Singh Avatar answered Nov 18 '22 15:11

MAhipal Singh


When using the script of nikdange_me I got:

error: exportArchive: ipatool failed with an exception: #<CmdSpec::NonZeroExcitException: ... >
error: Framework not found in dylib search path

So I altered it and used lipo -remove instead of lipo -extract and lipo -create which solved my problem:

# This script loops through the frameworks embedded in the application 
# and removes unused architectures.

find "${TARGET_BUILD_DIR}/${WRAPPER_NAME}" -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"
    for arch in $(lipo -archs $FRAMEWORK_EXECUTABLE_PATH); do
        if ! printf '%s\n' ${ARCHS[@]} | egrep -q "^$arch$"; then
            lipo -remove $arch "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH" 
        fi
    done
done
like image 6
Henrik Lineholm Avatar answered Nov 18 '22 17:11

Henrik Lineholm


For Run Script under Build phases, add following steps to the Run Script to remove x86_64 and/or i386:

cd "${ARTIFACTS_FOLDER}"/FrameworkName.framework

lipo -remove x86_64 FrameworkName -o FrameworkName
lipo -remove i386 FrameworkName -o FrameworkName

Can be combined for removing multiple architectures as:

lipo -remove x86_64 FrameworkName -o FrameworkName && lipo -remove i386 FrameworkName -o FrameworkName
like image 6
Alpana Avatar answered Nov 18 '22 17:11

Alpana