級(jí)別:★☆☆☆☆
標(biāo)簽:「Xcode Bitcode」「iOS Architecture」「arm64e」
作者: WYW
審校: QiShare團(tuán)隊(duì)
最近項(xiàng)目中接入某第三方SDK后,打包的時(shí)候發(fā)現(xiàn)有如下報(bào)錯(cuò):xxx.o was build without full bitcode error :
Linker command failed with exit code 1
。 然后經(jīng)過(guò)搜索,設(shè)置Enable Bitcode 為 NO
,就沒(méi)有這個(gè)報(bào)錯(cuò)了。筆者簡(jiǎn)單了解了一下Bitcode,今天給大家介紹一下。
Xcode之Bitcode
Bitcode
是Xcode7
的新特性。-
查看Bitcode:TARGETS -> Build Settings -> 搜索Enable Bitcode ,示意圖如下:
Xcode Bitcode
Bitcode的官方說(shuō)明:
官方:
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
是編譯后的程序的中間表現(xiàn),包含Bitcode
并上傳到App Store Connect
的Apps會(huì)在App Store
上編譯和鏈接。包含Bitcode
可以在不提交新版本App的情況下,允許Apple在將來(lái)的時(shí)候再次優(yōu)化你的App 二進(jìn)制文件。
對(duì)于iOS Apps,Enable bitcode
默認(rèn)為YES
,是可選的(可以改為NO)。對(duì)于WatchOS和tvOS,bitcode是強(qiáng)制的。如果你的App支持bitcode,App Bundle(項(xiàng)目中所有的target)中的所有的Apps和frameworks都需要包含Bitcode
。
看了以上內(nèi)容,我們就可以對(duì)Bitcode有一個(gè)簡(jiǎn)單的了解了。那么如果我們項(xiàng)目中在使用某些Framework或.a的時(shí)候,遇到了類似筆者遇到的錯(cuò)誤的時(shí)候,我們就需要查看所用的Framework或.a是否支持bitcode。
查看framework或者.a文件是否支持bitcode,支持哪些架構(gòu):
我們可以使用otool查看framework
或者.a
是否支持設(shè)置Enable Bitcode
為YES
,在終端中使用如下命令查看:
- otool -l framwork路徑下的實(shí)體文件 | grep __LLVM
說(shuō)明: 使用otool 工具 查看framework
文件的load commands
內(nèi)容,然后搜索load commands
中的__LLVM
。
如果上述命令的輸出結(jié)果有__LLVM
,那么就說(shuō)明,所用的framework
或.a
支持設(shè)置Enable bitcode
為YES
,否則不支持。
- 示例:
otool -l /Users/wangyongwang/Documents/QiBitcode/QiBitcode.framework/QiBitcode | grep __LLVM
如果上述命令沒(méi)有輸出結(jié)果,那么說(shuō)明所用的
framework
或.a
不支持設(shè)置Enable bitcode
為YES
;如果有如下的輸出結(jié)果,那么說(shuō)明所用的
framework
或.a
支持設(shè)置Enable bitcode
為YES
;
segname __LLVM
segname __LLVM
segname __LLVM
segname __LLVM
- App支持Enable Bitcode的必要條件:
- 使用的framework或者.a 文件支持設(shè)置 Enable bitcode為YES;
- 使用的framework或者.a 文件支持的架構(gòu)是齊全的;
- 那么為什么有些framework沒(méi)有做成支持Enable bitcode的方式呢?
我查到了如下資料:可能筆者自己理解上還有些問(wèn)題,筆者就不解讀了,大家自行解讀。
- 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支持的架構(gòu)有哪些:
先給大家介紹下lipo
lipo : Create or operate on a universal file: convert a universal binary to a single architecture file, or vice versa.
創(chuàng)建或者是操作一個(gè)通用文件,轉(zhuǎn)變通用文件為單獨(dú)的架構(gòu)文件或者反過(guò)來(lái)轉(zhuǎn)變單獨(dú)架構(gòu)文件為通用文件。
給大家介紹一下查看Framework支持的架構(gòu),這里我們會(huì)用到lipo info
。
lipo info
解讀
-info Briefly list the architecture types in the input universal file.
Lists the names of each archive.
簡(jiǎn)單地列舉出來(lái)輸入的通用文件的架構(gòu)類型,列舉出來(lái)每個(gè)架構(gòu)的名字:
- 使用方式:lipo -info framework或者.a實(shí)體文件路徑
- 使用示例:
lipo -info /Users/wangyongwang/Documents/QiBitcode/QiBitcode.framework/QiBitcode
結(jié)果示例:Architectures in the fat file:/Users/wangyongwang/Documents/QiBitcode/QiBitcode.framework/QiBitcode are: armv7 i386 x86_64 arm64
關(guān)于Architectures:
截止到2018年Apple新發(fā)布了iPhone XS, iPhone XS Max, iPhone XR后,iPhone及CPU對(duì)應(yīng)情況:
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 |
對(duì)于iPhone而言:iPhone 5S之前使用的是32位微處理器,iPhone 5S及之后都是64位的微處理器
模擬器上使用的CPU情況由所用的電腦確定
CPU | iPhone |
---|---|
i386 | 32 位微處理器 |
x86_64 | 64 位微處理器 |
了解更多iOS及相關(guān)新技術(shù),請(qǐng)關(guān)注我們的公眾號(hào):
關(guān)注我們的途徑有:
QiShare(簡(jiǎn)書)
QiShare(掘金)
QiShare(知乎)
QiShare(GitHub)
QiShare(CocoaChina)
QiShare(StackOverflow)
QiShare(微信公眾號(hào))
推薦文章:
iOS 重繪之drawRect
iOS 編寫高質(zhì)量Objective-C代碼(八)
iOS KVC與KVO簡(jiǎn)介
iOS 本地化(IB篇)
iOS 本地化(非IB篇)
奇舞周刊