17

我正在构建一个 iOS 静态库,我想为 bitcode 提供支持。为了实现这一点,我进入构建设置,搜索“自定义编译器标志”并添加 -fembed-bitcode。这将使用位码构建库,并且在 XCode 7 下一切正常。

但是,按照上面的方法,我失去了与 XCode 6 的向后兼容性。话虽如此,我必须向我的用户提供 2 个不同的库版本,一个带有位码标志,一个没有,因为不是每个人都升级到 XCode 7。

有没有办法让启用位码的库并具有向后兼容性而不必发布 2 个不同的版本?

更新:

你好@Vinicius Jarina 谢谢你的留言。我知道您可以创建一个胖库,我想这是一种常见的做法。到目前为止,我所做的是为这两种架构构建:

xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdK iphoneos 
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator

然后调用 lipo 打包到一个胖库中,例如:

lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/Versions/${FMK_VERSION}/${FMK_NAME}"

但是,我现在该怎么做?我根据这个链接尝试了这样的事情,但没有运气:

xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator
xcodebuild -configuration "Release" OTHER_CFLAGS='-fembed-bitcode' -target "${FMK_NAME}" -sdk iphonesimulator
xcodebuild -configuration "Release" OTHER_CFLAGS='-fembed-bitcode' -target "${FMK_NAME}" -sdk iphoneos

然后像这样创建一个胖库:

lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/Versions/${FMK_VERSION}/${FMK_NAME}"

如何在我的 scipt 中构建以包含两者,然后将它们打包到胖库中?

更新 2:

我终于设法完成了这项工作,并在这里列出了我的解决方案,供可能面临相同问题的其他人使用:

xcodebuild -configuration "Release" ENABLE_BITCODE=NO -target "${FMK_NAME}" -sdK iphoneos 
xcodebuild -configuration "Release" ENABLE_BITCODE=NO -target "${FMK_NAME}" -sdk iphonesimulator
xcodebuild -configuration "Release" ENABLE_BITCODE=YES -target "${FMK_NAME}" -sdk iphonesimulator
xcodebuild -configuration "Release" ENABLE_BITCODE=YES -target "${FMK_NAME}" -sdk iphoneos

然后像这样创建一个胖库:

lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/Versions/${FMK_VERSION}/${FMK_NAME}"
4

2 回答 2

7

您可以尝试使用不同的库创建一个胖库。

lipo -create -output libAndreasv.a libAndreasvBitcode.a libAndreasvARMv7.a libAndreasvARM64.a

这曾经适用于胖库(x86、x64、ARMv7、ARM64)也适用于位码。

于 2015-10-09T13:41:17.873 回答
0

也许我遗漏了一些东西,但我不相信你可以在胖库中拥有重复的架构,无论是否启用/禁用位码。例如,以下命令对我来说会导致错误:

lipo -create libcurl_iOS_bitcode.a libcurl_iOS_nobitcode.a -output libcurl_iOS_both.a

fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: libcurl_iOS_bitcode.a and libcurl_iOS_nobitcode.a have the same architectures (armv7) and can't be in the same fat output file
于 2015-11-10T19:53:13.730 回答