以前我们使用静态库中包含模拟器架构(x86_64)和真机架构(ARM)。上传至Appstore 打包时会自动把模拟器架构删除掉,但是使用动态库(包含x86_64架构)打包上传时不会自动删除掉模拟器架构(x86_64)而导致验证不通过。错误提示如下所示:
1. "Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]'."
2. "Invalid segment Alignment. The App Binary at XXXX.app/Frameworks/XXXX.framework/XX does not have proper segment alignment. Try rebuilding the app with the latest xcode version." (即便使用最新Xcode也是不行)
3. "The Binary is invalid. The encryption info in the LC_ENCRYPTION_INFO load command is either missing or invalid, or the binary is already encrypted. This binary does not seem to have been built with Apple's Linker."
解决方法
- 删除掉模拟器架构(x86_64),只保留真机架构(ARM)。
- 使用静态库打包。
- 使用脚本打包提交前 “手动” 删除掉不需要的架构。(推荐)
添加脚本步骤
-
新建脚本
屏幕快照 2016-12-15 11.28.22.png - 拷贝下面脚本至新建脚本中
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
参考
Stripping Unwanted Architectures From Dynamic Libraries In Xcode