Yesterday I was asked to merge multiple Libraries into one. This is a whole new area! Here is the background: Members of our department are developing three submodules of the main iOS application, and each submodule is a subproject of main application and output a
.a static library file and a
.bundle resource file. And now the head of our team wants to merge all the libraries into one and only expose this only one
.bundle file to the main application.
"And with minimum modification", said my boss.
What I Did
So I created a new project and make the current three subproject as subprojects of the new project. The new project has two target a
.a library and
.bundle resource. Both targets’ output are output of the merging of the three submodule accordingly.
The bundle file is just something like a folder, so merging is simply copying three folder into another. As of Xcode, go to
Build Phases -> Copy Bundle Resources and add subproject’s .bundle target.
The merging of
.a file are simple too, it’s only that I have never touched this area before.
Add the following line to
Build Phases -> Click "+" button on the topleft -> New Run Script Phase (Say we want merge
Minimum Modification, the only one is accessing bundle resources. Previously we get bundle from
MainBundle, but now we have to get the merged bundle first and then get the bundle we want in the merged bundle, which, I think, is qualified as
What I Learned
The solution above is not rigorous. One of the libraries might not support architectures that others do, so the might-not-supported architectures portion of the libraries should not be merged. The following command can figure out the architectures for which the library is being built:
The following command creates a thin version of the library with supported architectures in
A flat library is a library that support multiple architectures.