最初九月雪 / iOS / 在Xcode中从动态库剥离不需要的架构(90008...

分享

   

在Xcode中从动态库剥离不需要的架构(90008错误)

2018-03-01  最初九月雪

在Xcode中从动态库剥离不需要的架构

自从iOS 8发布以来,开发人员已经能够利用动态库对iOS开发的好处。对于一般开发,为所有需要的架构设置一个单一的动态库是非常好的,所以您可以在所有设备和iOS模拟器上运行,而无需更改任何东西。然而,这种方法有一个缺点 - 因为它们在运行时链接,当一个动态库被单独编译到最终应用程序时,不可能知道实际需要哪些架构。因此,Xcode将在编译时将整个事物复制到应用程序包中。除了浪费的磁盘空间,理论上没有真正的缺点。但是实际上,iTunes Connect不喜欢我们添加未使用的二进制切片:这时候,打包上传Appstore会报如下错误:

那么,我们如何解决这个问题呢?
步骤如下:

在Build Phases中加入run script。在里面添加Shell脚本,

APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
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

该脚本将查看您构建的应用程序的Frameworks文件夹,并确保只有您正在构建的架构存在于每个框架中。
好多了!现在我可以在我的项目中添加包含我所需要的所有架构的胖动态库,而我的构建过程将会在任何给定的时刻处理哪些架构。

 

可解决环信HyphenateLite.framework上传appstore报错:

在使用环信HyphenateLite.framework时,出现如下错误:

Code1:ERROR ITMS-90087: "Unsupported Architectures.

The executable for MM_FESCO.app/Frameworks/HyphenateLite.framework

contains unsupported architectures '[x86_64, i386]'."
ERROR ITMS-90087: "Unsupported Architectures.

The executable for MM_FESCO.app/Frameworks/HyphenateLite.framework

contains unsupported architectures '[x86_64, i386]'."
Code2:ERROR ITMS-90209: "Invalid Segment Alignment.

The app binary at 'MM_FESCO.app/Frameworks/HyphenateLite.framework/HyphenateLite'

does not have proper segment alignment. Try rebuilding the app with the latest Xcode version."
ERROR ITMS-90209: "Invalid Segment Alignment.

The app binary at 'MM_FESCO.app/Frameworks/HyphenateLite.framework/HyphenateLite'

does not have proper segment alignment. Try rebuilding the app with the latest Xcode version."
Code3:ERROR ITMS-90125: "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."
ERROR ITMS-90125: "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."
Code4:WARNING ITMS-90080: "The executable 'Payload/MM_FESCO.app/Frameworks/HyphenateLite.framework'

is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables.

For more information refer to Technical Q&A QA1788 - Building a Position Independent Executable in the iOS Developer Library."
WARNING ITMS-90080: "The executable 'Payload/MM_FESCO.app/Frameworks/HyphenateLite.framework'

is not a Position Independent Executable.

Please ensure that your build settings are configured to create PIE executables.

For more information refer to Technical Q&A QA1788 -

Building a Position Independent Executable in the iOS Developer Library."

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多
    喜欢该文的人也喜欢 更多

    ×
    ×

    ¥.00

    微信或支付宝扫码支付:

    开通即同意《个图VIP服务协议》

    全部>>