Our iOS project uses Swift+Objective-C hybrid development, and for a long time we used use_frameworks in our Podfile! That is, make all the Pods Dynamic Framework. Wechat and other third-party SDKS are provided to developers in the form of a static library. A, so we cannot directly rely on it, and will report errors like XXX has transitive dependencies that include static binaries. So we had to wrap.A into a dynamic framework before we could integrate it into the project through Cocoapods.

The basic concept

  • Static library: A package of object files. The link will be completely copied to the executable file, there is a problem of multiple executables containing the same static library code.
  • Dynamic library: an executable without the main function. When linking, the code is not copied. After the program is started, it is loaded with DYLD, and then symbols are determined. Therefore, a dynamic library can be used for multiple programs to dynamically link to achieve the purpose of saving memory.

A pit

There are many articles on the process of making Dynamic Framework. I mainly refer to the componentization – Dynamic library practice article here. Thanks again to the author of this article @Nanzhi Dihan Step by step, more than 90% of the work can be completed. The reason why it is not 100% is that we have encountered the support problem of CPU instruction set in actual production, which requires special attention to the following points:

  • For Mach-O Type, choose Dynamic Library
  • Buld Setting -all_load for Other Linker Flags, otherwise some files may not be integrated into the framework
  • Buld Setting Build Active Architecture Only select No
  • Instruction set and, the author attached script in the article, can make the generated framework colleagues support emulators and real machine CPU allowed, great! The framwork is ready to uselipo -infoView supported CPU architecturesArchitectures in the fat file: XXX are: i386 x86_64 armv7 arm64Indicates that both the simulator and the real machine are supported, and can be used.

Pit 2

The Dynamic framework is built and integrated into the main project through Cocoapods. Debug, run everything OK. Finally to pack online, as expected hung up!! The error prompt

bitcode bundle could not be generated because
 xxx was built without full bitcode.
All object files and libraries for bitcode must be generated from Xcode Archive or Install build for architecture armv7 

Copy the code

So it’s Google again. Finally, I found a solution in this article. I also imagined -fembed-bitcode-marker and -fembed-bitcode. So in the Bulid Settings of the Dy Namic Framework, I did the following

  • Enable Bitcode = Yes
  • -fembed-bitcode was added to Other C Flags
  • Add BITCODE_GENERATION_MODE=bitcode to user-defined

Then build a new framework and integrate it into the main project and Archive it. Finally, stable!