Recently, several base libraries in the project have been packaged into dynamic libraries to reduce the binary package size. There were no problems with the native build. However, the following error occurred on Jenkins:

Error Domain=IDEFoundationErrorDomain Code=1 "Failed to verify bitcode in FLAnimatedImage.framework/FLAnimatedImage: error: Bundle only contains bitcode-markerCopy the code

After searching, it was found to be related to Bitcode. Since these libraries support bitcode by default, the compile parameter at build time is -fembed-bitcode-marker, which simply marks bitcode in the binary, but actually has no content, and is generally used for testing.

However, when we package on Jenkins, we archive the IPA package first and then export it. The compilation parameter of archive is -fembed-bitcode, so it is different from local debugging.

So, what’s the difference between these two parameters?

[StackOverFlow answer] (https://stackoverflow.com/questions/31233395/ios-library-to-bitcode) said more clearly.

• -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, • Xcode itself builds with -fembed-bitcode-marker for. Xcode builds with -fembed-bitcode-marker for • Xcode only builds with -fembed-bitcode for archive builds/production builds (as this is only needed for Apple).

-fembed-bitcode-marker will generate a minimum bitcode section with no content, size=1.

-fembed-bitcode Generates bitcode content.

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.

So when we package lib, we need to set the parameter -fembed-bitcode to include the content of bitcode.

Therefore, there are two solutions:

  • Disable bitcode

  • Set the parameter -fembed-bitcode

How to Set parameters

Since I am packaging based on pod package, I need to change the podSpec file and add xcConfig.

s.xcconfig = {'BITCODE_GENERATION_MODE'= >'bitcode'}
Copy the code

In addition, when using POD package, if the library is a dynamic library, there will be a problem, I will change the source code, and will write another article about it.

If you are using XcodeBuild to package lib, you can add it to the user-define Setting of build setting, so it will also be -fembed-bitcode for build.

'BITCODE_GENERATION_MODE'= >'bitcode'
Copy the code

The diagram below:

If you want -fembed-bitcode-marker, set it to marker

'BITCODE_GENERATION_MODE'= >'marker'
Copy the code

This picture is quite clear:

The Other option is to set it directly to Other C Flags. But I haven’t tried it yet. Setting BITCODE_GENERATION_MODE is recommended.

(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’)

How do I check that the generated lib is correct

You can check whether the lib parameter is -fembed-bitcode-marker or -fembed-bitcode.

Enter in terminal

otool -arch armv7 -l xx.a/xx.framework
Copy the code

Note: If lib contains the emulator architecture, you need to specify the arch of the corresponding real machine to see it.

Then, Ctrl+F, search __bundle and the following should appear:

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
Copy the code

If the size is not 1, it indicates -fembed-bitcode.

If the result is -fembed-bitcode-marker as shown in the following figure, it indicates that we are not packing correctly.

Also, to check whether the lib supports bitcode, run the following command to check whether __LLVM is present.

otool -arch armv7 -l xx.a/xx.framework | grep __LLVM
Copy the code