最近,在将工程中的几个基础库打包成动态库,减小二进制包大小。在本机build时没出现啥问题。可是在jenkins上打包,却出现了以下错误:ios
Error Domain=IDEFoundationErrorDomain Code=1 "Failed to verify bitcode in FLAnimatedImage.framework/FLAnimatedImage: error: Bundle only contains bitcode-marker 复制代码
经搜索,发现跟bitcode相关。由于这些库默认是支持bitcode的,在build时,compile的参数是-fembed-bitcode-marker
,它的意思只是标记二进制文件中有bitcode,可是实际上没有内容,通常用于测试。xcode
而咱们在jenkins上打包时,先archive,而后再导出ipa包,而archive的编译参数是-fembed-bitcode
,因此与本地调试不太同样。bash
那么,这两个参数有什么区别呢?架构
[StackOverFlow上的回答](https://stackoverflow.com/questions/31233395/ios-library-to-bitcode)说的比较清楚。测试
• -fembed-bitcode-marker simply marks where the bitcode would be in the binary after an archive build. • -fembed-bitcode actually does the full bitcode generation and embedding, so this is what you need to use for building static libraries. • Xcode itself builds with -fembed-bitcode-marker for regular builds (like deploy to simulator) • Xcode only builds with -fembed-bitcode for archive builds / production builds (as this is only needed for Apple).ui
-fembed-bitcode-marker
会生成一个最小bitcode的section,可是没有任何内容,size=1。this
-fembed-bitcode
则会生成bitcode的相关内容。spa
You should be aware that a normal build with the -fembed-bitcode-marker option will produce minimal size embedded bitcode sections without any real content. This is done as a way of testing the bitcode-related aspects of your build without slowing down the build process. The actual bitcode content is included when you do an Archive build.调试
因此咱们在打包lib的时候,须要设置参数-fembed-bitcode
,这样才会包含bitcode的内容。code
所以,解决方案有两种:
禁用bitcode
设置参数-fembed-bitcode
因为我是基于pod package来打包,因此须要需改podspec文件,添加xcconfig便可。
s.xcconfig = {'BITCODE_GENERATION_MODE' => 'bitcode'}
复制代码
这里插一句,在用pod package打包时,若是依赖的库是动态库时,会有问题,我本身将源码改了下,会另外写一篇文章说说。
若是你是经过xcodebuild来打包lib的话,能够在build setting的User-Define Setting中添加,这样在build的时候也会是-fembed-bitcode
。
'BITCODE_GENERATION_MODE' => 'bitcode'
复制代码
以下图:
若是想让参数是-fembed-bitcode-marker
,设置为marker
'BITCODE_GENERATION_MODE' => 'marker'
复制代码
这张图表达的比较清晰:
另外还有一个种方式是直接在Other C flags里设置,网上说会产生warning。不过我还没尝试过。推荐使用设置BITCODE_GENERATION_MODE的方式。
(When I tested using the -fembed-bitcode on the Other C flags, Xcode gave the warning clang: warning: argument unused during compilation: '-fembed-bitcode-marker')
可经过如下方式查看,打出的lib参数是-fembed-bitcode-marker
仍是-fembed-bitcode
。
在terminal中输入
otool -arch armv7 -l xx.a/xx.framework
复制代码
注意:若是lib包含了模拟器架构,则须要指定相应真机的arch才能看获得。
而后,Ctrl+F,搜索__bundle,应该会出现如下内容:
Section
sectname __bundle
segname __LLVM
addr 0x0002c000
size 0x000b0a09
offset 180224
align 2^0 (1)
reloff 0
nreloc 0
flags 0x00000000
reserved1 0
reserved2 0
复制代码
若是size不为1,则说明是-fembed-bitcode
。
若是结果以下图,则是-fembed-bitcode-marker
,说明咱们打的包不对。
另外,若是要查看lib是否支持bitcode,可执行以下命令,查看是否有__LLVM
。
otool -arch armv7 -l xx.a/xx.framework | grep __LLVM
复制代码