iOS library to BitCode

南楼画角 提交于 2019-11-26 21:26:11
Danoli3

When building static libraries you must add the following for bitcode generation:

-fembed-bitcode 

for a dynamic library you need to additionally link with

-fembed-bitcode

Note: This command is only available with Xcode7+

In regards to the accepted answer of using -fembed-bitcode-marker

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.

bwilson Apple Staff. https://forums.developer.apple.com/thread/3971#12225


To be more specific:

  • -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).
Gautam Jain

Go the Build Settings. Search for "custom compiler flags".
Add -fembed-bitcode to Other C Flags. This will ensure that the lib is built with bitcode compatibility at compile time. I made this for iOS 64 bit and 32 bit, and lipo'd them into one. Works like a charm.

Since you guys had queries, here's a screenshot of the settings: The settings are same for the project target and the SDK target.


The bitcode lib will not work with Xcode 6.

If you're still having trouble after adding the -fembed-bitcode to the Other C flags, search for "Enable Bitcode" under "Build Options" and set it to No. This will allow you to archive properly.

Xeieshan

What you need is -fembed-bitcode. When ENABLE_BITCODE is enabled, Xcode builds with -fembed-bitcode-marker for regular builds and with -fembed-bitcode for archive builds. One option simply "marks" where the bitcode would be in the binary after an archive build and enforces the new bitcode rules, while the other actually does the full-on bitcode generation, which is likely slower and thus not enabled on every kind of build.

Syo Ikeda's guide to handling BITCODE might also help you:

You can find the full slide deck here.

If you are building a Static Library and would like to enable the bitcode, just the (1) ENABLE_BITCODE = YES may not be enough.

(2) Also with the setting -fembed-bitcode the error below was still being thrown for multiple files when built in Teamcity

bitcode bundle could not be generated because ‘/path/fileInYourStaticLib.a(fileInYourStaticLib.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

Few tips/things to consider that helped me to ultimately solve the issue, in addition to the above steps (1) and (2)

  1. Make Sure you set the variable 'Other C Flags' to "-fembed-bitcode" on the 'PROJECT', and all the 'TARGETS'.

  2. If there are multiple projects that you are trying to create a static library for, make sure all the projects have "-fembed-bitcode" enabled.

  3. On Build Settings, click on the + sign at the top to add a user-defined build setting with the nameBITCODE_GENERATION_MODE, and set Debug tomarker, Release tobitcode

  4. If the above steps doesn't work, you can also try this option. On Build Settings -> Other C flags, set Debug to-fembed-bitcode-marker, and Release to-fembed-bitcode

This blog was of great help https://medium.com/@heitorburger/static-libraries-frameworks-and-bitcode-6d8f784478a9

Also every time you make the above changes, try deleting the DerivedData, Clean the XCode Project, and possibly quit and restart XCode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!