How to create iOS fat frameworks, libraries and thin XCFrameworks

German Velibekov
3 min readJan 23, 2020

I am going to introduce you to my short scripts, written on bash, for creating fat frameworks, libraries and xcframeworks. Those of you who have encountered with 3rd party code distribution on iOS must have heard those terms and must know that this topic is nebulous and ill-defined. Apple also doesn’t provide clear documentation on how to create these frameworks as they do for other subjects (at least I haven’t found any). However, even if you haven’t been exposed to these terms before, I hope you will still find this article relevant and it will serve as a useful reference.

Before we begin, I’d like to recognize the organization I have been working at. Thank you to the folks at Bank Hapoalim graciously agreeing to share this knowledge with other script enthusiasts.

Creating fat frameworks

In my opinion, frameworks are the most popular distributed type of source code, so let’s start there.

create-fat-framework.sh

Every building script has a similar structure, containing two parts

  • building framework/s, and
  • creating a fat version of that framework/s

The script receives three arguments: a path to a workspace, build configuration, output folder and a list of frameworks. Each framework name should match an Xcode scheme within a project that builds that framework. For instance, with a workspace named BuildTestFramework and a target named FancyFramework, we would run the script as follows:

create-fat-framework.sh -w BuildTestFramework.workspace -c Release -o {path-to-output-folder} FancyFramework

The building phase is done through an Xcode command-line tool named xcodebuild , whereas a fat version is created using lipo. Build derived data is placed into /tmp folder.

Note: The current version of script was built to support Xcode Workspace-type project. To change it for a regular project, just replace -workspaceparameter within xcodebuild to -project .

Creating fat static libraries

Not far below frameworks in popularity are static libraries. Without any further introduction, let’s get down to brass tacks.

create-fat-library.sh

This script is based on the same principle as the first one. Two stages, th e same parameters, but this time the script is suited to a static library target. During the last step, the script copies an include folder where all the library’s public headers should be placed.

Create XCFramework

Although we didn’t need it for our project, I wrote this script as a bonus, especially for you folks. As you might guess, it is also based on the same idea as the scripts above.

create-xcframework.sh

Aggregation Target

There’s a special type of Xcode target which is used to store and run these kinds of scripts. The advantage of using such a method is that the target has access to Xcode variables. Personally, I prefer to run the scripts outside the IDE so as to always have the option to easily run them externally, from a CD 💿, for instance. (CD = Continues Delivery, not the one I loved to put into my CD player when I was trying to look like a cool teenager 😎).

Conclusion

First, feel free to use these scripts as you desire! They can be altered; for instance, you can add fancy and sophisticated phases as has been done here. All in all, I understand that this article doesn’t cover all the possible cases and tweaks. However, I do believe that it provides you with a good base — someplace to begin. And as we all know, perhaps that’s the hardest part of any enterprise.

In conclusion, I’d like to clarify a few things. The post you have read is just an assembly of brilliant work done by casual people like you and me. I am sure they have put a lot of energy into accomplishing their goals and they have been kind enough to share their work with us. So I want to thank Ryan Lepinski, Santhosh K, Hassan Ahmed Khan, Andrea Miotto, deszip. Without you guys, this post wouldn’t have existed.

References

--

--