iOS中 bitcode 的故事

文章出处,原创于 https://HawkingOuYang.github.io/

我的GitHub


遇见问题:bitcode
1
2
3
4
5
ld: bitcode bundle could not be generated because '/Users/OYXJ/Desktop/HomeTime/app/trunk/HomeTime_mobileUI/Project/Src/Library/SDKs/libLeTVLoginSDK/libLeTVLoginSDK.a(Pods-LeTVLoginSDK-dummy.o)' was built without full bitcode. All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ld: bitcode bundle could not be generated because '/Users/OYXJ/Desktop/HomeTime/app/trunk/HomeTime_mobileUI/CustomFramework/CAbstractManager.framework/CAbstractManager' was built without full bitcode. All frameworks and dylibs for bitcode must be generated from Xcode Archive or Install build for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

检验是否支持bitcode

针对于静态链接库.framework文件

1
otool -l libWeiboSDK.a | grep LLVM

针对于静态链接库.a文件

1
otool -arch armv7 -l xxxx.a | grep __bitcode | wc -l

1
2
3
4
I was able to fix this by adding "-fembed-bitcode" to Other C Flags of the project I am building a static lib of.
It will give you a warning because a normal build adds "-fembed-bitcode-marker" but -fembed-bitcode takes precedence over the dummy marker.
需要在所有的.a库在bundlsetting Other C Flags 添加-fembed-bitcode 或者你打包.a的编译添加上此选项。

Bitcode适配指南

这个方法已经过时了:
Building WebRTC with Bitcode,
估计要用官方的方法:
WebRTC Enable bitcode on iOS
参考:
chromium.org

1
2
3
4
5
6
7
最近才提交的Message was sent while issue was closed.
On 2016/11/09 12:58:23, commit-bot: I haz the power wrote:
Patchset 2 (id:??) landed as
https://crrev.com/592baaf89aaf79245a55bfd3dbf47371b486cd03
Cr-Commit-Position: refs/heads/master@{#14997}
Can you check that this doesn't break the framework builder?
解释问题:bitcode

Xcode开启bitcode,然后archive,到处ipa之前,提示如下:

.xcarchive 文件的目录结构(注意不要泄漏符号文件dSYM),如图:Fat_binary

Impact of Xcode build options “Enable bitcode” Yes/No

What is bitcode ?

bitcode 是趋势,不可避免 要支持bitcode ——> 根本原因在于:app越做越大,越来越多样化,硬件的cpu架构也比较多,很多用户的手机只有16G,所以要给app瘦身(减小安装包的大小)。总之:bitcode是针对于 硬件平台 (cpu架构,模拟器 x86 32 and 64 bit modes,设备:arm6/arm7/arm7s/arm64 等;屏幕尺寸 以及 分辨率@1x, @2x, @3x 等);软件平台(操作系统 iOS8、iOS9、iOS10 等),编译器 (LLVM、gcc、g++ 等)

For distribution in the App Store, Apple will create separate versions of your app for each machine architecture (arm6/arm7/arm7s/arm64) instead of one app with a fat binary. This means the app installed on iOS devices will be smaller.

In Xcode project target build settings, What is Mach-O Type?

可行方案:bitcode

们没针对所有的硬件平台编译
armv7 arm64 armv7s

debug是可以编过的 应该就是没编译所有硬件架构导致的

我让他们重新编译一下

release是全平台的

你们应该都是debug

我是release模式下

方案总结:bitcode

1、bitcode 是趋势,不可避免 要支持bitcode ——> 根本原因在于:app越做越大,越来越多样化,很多用户的手机只有16G,所以要给app瘦身(减小安装包的大小)
Impact of Xcode build options “Enable bitcode” Yes/No
http://stackoverflow.com/questions/31088618/impact-of-xcode-build-options-enable-bitcode-yes-no

2、开启bitcode没法看crash的函数栈 ——> 之前存在这个问题,现在已经有成熟的解决方案。
Downloading Bitcode dSYMs
https://docs.fabric.io/apple/crashlytics/missing-dsyms.html

3、要能支持 但暂时不需要开启bitcode ——> CCoreData.framework CAbstractManager.framework 要能支持,这两个独立的工程 编译的时候 就得打开 bitcode

4、三方库 以后能不能支持bitcode ——> 三方库 也是 在 HomeTime工程里编译的,所以 能 支持 bitcode.

5、WebRTC.framework LeFaceSDK.framework 应该也能支持(这两个工程编译之前 打开 bitcode),但实际情况 需要 试验一把。

6、AppStore 审核 应该会过,Apple既然 这么提倡,我们 按照 Apple的要求做了,审核 应该会过。

7、为了 加快 这次的 送审 速度,我已经 把 CCoreData.framework CAbstractManager.framework 改成 不支持 bitcode,并且提交SVN。

fabric

Downloading Bitcode dSYMs
https://docs.fabric.io/apple/crashlytics/missing-dsyms.html

For Bitcode enabled builds that have been released to the iTunes store or submitted to TestFlight, Apple generates new dSYMs. You’ll need to download the regenerated dSYMs from Xcode and then upload them to Crashlytics so that we can symbolicate crashes.

dSYMs for Bitcode enabled apps can be downloaded from Xcode’s Organizer. Select the specific Archive of your app and then hit the “Download dSYMs…” button which will insert the Bitcode compiled dSYMs into the original Archive. Then, manually upload the dSYM to Crashlytics via the “Uploading Missing Bitcode dSYM” instructions.