如何解决Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]

问题

APP改版测试后准备Archive发布时,结果居然出现题目中的错误提示。查了一下,如果archive的时候没有选iOS Devices而是模拟器,会出现这个错误提示。
另一种情况就是我项目中的:用到了一些其它的结构包含x86_64, i386的framework。

解决方法

可以在终端使用

$ lipo -info workspacePath/XXX.framework/XXX 命令来检查一下framework。
解决方法是生成binary的时候使用一段script来去掉那些不支持的结构。
在Xcode中选择项目->TARGETS->Build Phases, 找到Embed Framework。
然后在Xcode的菜单栏Editor->Add Build Phase->Add Run Scrip Build Phase。

如下图:

如何解决Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]_第1张图片
upload-images.png

于是在Embed Framework下面会出现Run Script。
Shell填入:/bin/sh
下面输入这段script:

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

操作如下图:

如何解决Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]_第2张图片
upload_images.png

然后重新Archive即可。

版权声明:本文为博主原创文章,未经博主允许不得转载。

你可能感兴趣的:(如何解决Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386])