[iOS] watchOS 使用 .a 库时出现 ld: bitcode bundle could not be generated 错误

0、编译环境:
OSX Yosemite 10.10.5
Xcode 7.1
watchOS 2.0

1、问题描述:
在升级 Xcode 7.0 后,编译 watchOS 版本静态库如果依然是用 build 目录下的 Release-watchos 里面的 .a 就有可能出现如下 ld: bitcode bundle could not be generated 错误:
b1

这里面说你有库没有生成 bitcode 代码。但是库和库的依赖都已经打开 Enable bitcode 选项了:
b2

这是什么问题呢?其实这段错误里面已经给了我们提示:
All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture armv7k

也就是说我们要用 Archive 模式生成相应的库。

2、问题解决:
1)使用 Archive 模式生成库
首先点击你的 watchOS target,然后将 Scheme 切换为真机模式(Generic iOS Device),如图所示:
test1

2)编译 Archive 版本库:
点击菜单 Product -> Archive,如图所示:
Screen Shot 2015-10-28 at 2.43.20 PM

3)找到并 copy 生成 Archive 库:
找到生成 Archive 库地址方法如图所示:
test2

然后将 .a 库替换成这个就好了!

3、补充问题:
苹果官方 Xcode 7.0 Release Node 说明已经修复了这个错误:
Building
Fixed: If your iOS app embedded a watchOS app and you had a framework for both iOS and watchOS embedded in each app, your project would fail to build when you performed the Archive action. (22183332)

不过就我刚刚升级的 7.1 版本来说,这一问题依然是存在的。

参考文献:
[1] https://developer.apple.com/library/watchos/releasenotes/DeveloperTools/RN-Xcode/Chapters/xc7_release_notes.html

Add a Comment

您的电子邮箱地址不会被公开。 必填项已用*标注