Xcode发布报错Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]

今天打包上传iOS包,碰到一个三方库的坑,我用的是react-native开发,不过跟原生上传发布没区别,用到了一个多张图片上传npm包,打包上传到itunes connect的时候遇到一个报错:Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]

对于一般开发,为所有需要的架构设置一个单一的动态库是非常好的,因此您可以在所有设备和iOS模拟器上运行,而无需更改任何内容。

但是因为它们在运行时链接,当一个动态库被单独编译到最终应用程序时,不可能知道实际需要哪些架构,因此,Xcode将在编译时将整个事物复制到应用程序包中,然而你不能向App Store提交不支持的体系结构的二进制文件,因此解决方案是在提交之前从最终二进制文件中“手动”删除不需要的体系结构。

所以解决方法是生成binary的时候使用一段script来去掉那些不支持的结构。
在Xcode中选择项目->targets->Build Phases, 找到Embed Framework。
然后在Xcode的菜单栏Editor->Add Build Phase->Add Run Scrip Build Phase。
于是在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

如下图


Xcode发布报错Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386]_第1张图片
WechatIMG1.jpeg

这个脚本只要运行不用于模拟器(这意味着目标文件夹不像“Debug-iphonesimulator”),则从fat二进制文件中删除i386和x86_64片段(如果它们存在)。
大功告成,然后重新archive即可。

你可能感兴趣的:(Xcode发布报错Unsupported Architecture. Your executable contains unsupported architecture '[x86_64, i386])