iOS 了解Xcode Bitcode

级别:★☆☆☆☆
标签:「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 ,示意图如下:
    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,否则不支持。

  • 示例:
 otool -l /Users/wangyongwang/Documents/QiBitcode/QiBitcode.framework/QiBitcode | grep __LLVM
  1. 如果上述命令没有输出结果,那么说明所用的framework.a不支持设置Enable bitcodeYES

  2. 如果有如下的输出结果,那么说明所用的framework.a支持设置Enable bitcodeYES

   segname __LLVM
   segname __LLVM
   segname __LLVM
   segname __LLVM
  • App支持Enable Bitcode的必要条件:
  1. 使用的framework或者.a 文件支持设置 Enable bitcode为YES;
  2. 使用的framework或者.a 文件支持的架构是齐全的;
  • 那么为什么有些framework没有做成支持Enable bitcode的方式呢?

我查到了如下资料:可能笔者自己理解上还有些问题,笔者就不解读了,大家自行解读。

  1. Build static library or framework via Xcode 7, while user build application using Xcode 6.
    "Framework and library providers need to include bitcode for Xcode 7 development, and Xcode 7 generates bitcode by default.

However, bitcode-enabled framework and library products do not work well with Xcode 6. If you still need to support Xcode 6 development,
you must produce an additional version of your products without bitcode.
To build a library without bitcode, either use Xcode 7 with the build setting Enable Bitcode disabled (ENABLE_BITCODE=NO)
or use Xcode 6."

  • 查看framework支持的架构有哪些:

先给大家介绍下lipo

lipo : Create or operate on a universal file: convert a universal binary to a single architecture file, or vice versa.
创建或者是操作一个通用文件,转变通用文件为单独的架构文件或者反过来转变单独架构文件为通用文件。

给大家介绍一下查看Framework支持的架构,这里我们会用到lipo info

lipo info解读

-info Briefly list the architecture types in the input universal file.
Lists the names of each archive.
简单地列举出来输入的通用文件的架构类型,列举出来每个架构的名字:

  • 使用方式:lipo -info framework或者.a实体文件路径
  • 使用示例:
 lipo -info /Users/wangyongwang/Documents/QiBitcode/QiBitcode.framework/QiBitcode

结果示例:Architectures in the fat file:/Users/wangyongwang/Documents/QiBitcode/QiBitcode.framework/QiBitcode are: armv7 i386 x86_64 arm64

关于Architectures:

截止到2018年Apple新发布了iPhone XS, iPhone XS Max, iPhone XR后,iPhone及CPU对应情况:

CPU iPhone
armv6 iPhone, iPhone 3G
armv7 iPhone 3GS, iPhone4(GSM),iPhone 4(CDMA),iPhone 4S
armv7s iPhone 5, iPhone 5C
arm64 iPhone 5S, iPhone SE, iPhone 6, iPhone 6 Plus, iPhone 6s, iPhone 6s Plus, iPhone 7, iPhone 7 Plus, iPhone 8, iPhone 8 Plus, iPhone X
arm64e iPhone XS, iPhone XS Max, iPhone XR

对于iPhone而言:iPhone 5S之前使用的是32位微处理器,iPhone 5S及之后都是64位的微处理器

模拟器上使用的CPU情况由所用的电脑确定

CPU iPhone
i386 32 位微处理器
x86_64 64 位微处理器

了解更多iOS及相关新技术,请关注我们的公众号:

关注我们的途径有:
QiShare(简书)
QiShare(掘金)
QiShare(知乎)
QiShare(GitHub)
QiShare(CocoaChina)
QiShare(StackOverflow)
QiShare(微信公众号)

推荐文章:
iOS 重绘之drawRect
iOS 编写高质量Objective-C代码(八)
iOS KVC与KVO简介
iOS 本地化(IB篇)
iOS 本地化(非IB篇)
奇舞周刊

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 151,511评论 1 330
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 64,495评论 1 273
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 101,595评论 0 225
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 42,558评论 0 190
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 50,715评论 3 270
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 39,672评论 1 192
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,112评论 2 291
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 29,837评论 0 181
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 33,417评论 0 228
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 29,928评论 2 232
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,316评论 1 242
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 27,773评论 2 234
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,253评论 3 220
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 25,827评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,440评论 0 180
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 34,523评论 2 249
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 34,583评论 2 249

推荐阅读更多精彩内容