如何检查框架是否支持 Xcode7 的 Bitcode

How to check if a framework is Bitcode supported for Xcode7

从Xcode7开始成为第三方框架应该支持的通病之一Bitcode。我们还可以通过在构建设置中将 ENABLE_BITCODE 设置为 NO 来禁用 BITCODE。但我不想关闭它,而是想将我所有的框架转换为 BITCODE 兼容。

那么除了在Xcode中编译框架之外,如何检查框架是否兼容BITCODE。有时 Xcode 给出一个框架的 BITCODE 兼容性错误,即使其他框架不支持 BITCODE,也会留下其他框架。

是否有任何tool/command行检查?

来自 this Apple Developers Forum discussion, user dshirley and bwilson 建议使用命令行工具 otoolgrep 检查位码部分是否存在。

$ otool -l libName.o | grep __LLVM

$ otool -l MyFramework.framework/Versions/A/MyFramework | grep __LLVM

运行 上面的命令,如果库包含 bitcode 你会看到 segname __LLVM 输出。

接受的答案建议您应该 grep __LLVM 但我宁愿这样做

otool -l libName.o | grep __bitcode

因为有不同的 __LLVM 段,并不是所有这些都表明存在 Bitcode。这是一个例子:

Section
  sectname __bitcode
   segname __LLVM
      addr 0x00000000000007d0
      size 0x0000000000000f10
    offset 3360
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __cmdline
   segname __LLVM
      addr 0x00000000000016e0
      size 0x0000000000000069
    offset 7216
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0

__cmdline 部分的存在并不表示存在 Bitcode,但在搜索 __LLVM.

时也会找到它

您可以尝试这些命令:

otool -arch armv7 -l libDeviceManager.a | grep bit code

otool -arch arm64 -l libDeviceManager.a | grep bitcode

我观察到 __bitcode 部分仅适用于静态库,不适用于动态库。因此,一种解决方案是以下命令。

otool -l libDeviceManager.a | grep __LLVM 

此外,有时使用胖二进制文件 otool 可能不会提供 __LLVM 段,即使它们存在。对于这些情况,您可以使用以下命令

otool -arch armv7 -l libDeviceManager.framework/libDeviceManager | grep __LLVM

Targets 中设置标志:

已启用位码

otool -arch arm64 -l myFramework | grep __LLVM
  segname __LLVM
   segname __LLVM

我(错误地)期望针对本地 iOS 应用构建读取相同的输出。事实并非如此。尽管有 ENABLE_BITCODE YES,但相同的命令没有产生任何结果。只有当您选择 Archive 时,bitcode 进程才会启动。

这个答案对我有帮助:

另一种方法

otool -v -s __LLVM __bundle <binary_path>
//e.g.
otool -v -s __LLVM __bundle "/Users/alex/MyModule.framework/MyModule" 

或在 __LLVM

中查找 __bundle 部分
otool -l <binary_path> | grep __bundle