iOS 了解Xcode Bitcode

iOS 了解Xcode Bitcode

https://www.jianshu.com/p/4fa8168e2892

级别:★☆☆☆☆
标签:「Xcode Bitcode」「iOS Architecture」「arm64e」
作者: WYW
审校: QiShare团队

最近项目中接入某第三方SDK后,打包的时候发现有如下报错:xxx.o was build without full bitcode error :Linker command failed with exit code 1。 然后经过搜索,设置Enable Bitcode 为 NO,就没有这个报错了。笔者简单了解了一下Bitcode,今天给大家介绍一下。

Xcode之Bitcode

  • BitcodeXcode7的新特性。
  • 查看Bitcode:TARGETS -> Build Settings -> 搜索Enable Bitcode ,示意图如下:

    iOS 了解Xcode Bitcode

    Xcode Bitcode

Bitcode的官方说明

官方:
Bitcode is an intermediate representation of a compiled program. apps you upload to App Store Connect that contain bitcode will be compiled and linked on the App Store. Including bitcode will allow Apple to re-optimize your app binary in the future without the need to submit a new version of your app to the App Store.
For iOS apps, bitcode is the default, but optional. For watchOS and tvOS apps, bitcode is required. If you provide bitcode, all apps and frameworks in the app bundle (all targets in the project) need to include bitcode.

翻译:
Bitcode是编译后的程序的中间表现,包含Bitcode并上传到App Store Connect的Apps会在App Store上编译和链接。包含Bitcode可以在不提交新版本App的情况下,允许Apple在将来的时候再次优化你的App 二进制文件。
对于iOS Apps,Enable bitcode 默认为YES,是可选的(可以改为NO)。对于WatchOS和tvOS,bitcode是强制的。如果你的App支持bitcode,App Bundle(项目中所有的target)中的所有的Apps和frameworks都需要包含Bitcode

看了以上内容,我们就可以对Bitcode有一个简单的了解了。那么如果我们项目中在使用某些Framework或.a的时候,遇到了类似笔者遇到的错误的时候,我们就需要查看所用的Framework或.a是否支持bitcode

查看framework或者.a文件是否支持bitcode,支持哪些架构:

  • 首先给大家介绍一个工具:otool
  • 说明:
    otoolobject file display tool.
    用于查看object file的工具。

我们可以使用otool查看framework或者.a 是否支持设置Enable BitcodeYES,在终端中使用如下命令查看:

  • otool -l framwork路径下的实体文件 | grep __LLVM

说明: 使用otool 工具 查看framework文件的load commands内容,然后搜索load commands中的__LLVM

如果上述命令的输出结果有__LLVM,那么就说明,所用的framework.a支持设置Enable bitcodeYES,否则不支持。

  • 示例:



作者:QiShare
链接:https://www.jianshu.com/p/4fa8168e2892
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。