Universal or Fat static library

This post is about how to create universal or fat library and presuming that you already know how to create a static library. We generally use third party static library which works mostly across all architectures (i386, armv7, armv7s, arm64). These libraries have all the slices, one slice for an architecture. So, the more number of architecture you support the bigger the size of library will be.

Enough said now the steps:

1. Include all the architectures you need under architecture and valid architecture section as shown in screenshot.

Screen Shot 2015-06-20 at 8.32.19 pm

2. Select target device as simulator and run the project.

3. Select target device as iOS device and run the project.

Screen Shot 2015-06-20 at 8.03.39 pm

4. Copy two folders Debug-iphoneos and Debug-iphonesimulator to desktop.

5. Open terminal and type : lipo -create  path of .a file from iphonesimulator folder        path of .a file from iphoneos folder   -output universallib.a

6. Instead of writing path of file you can drag the .a file directly to terminal.

7. Done! you can find the universal library in your home directory.

8. Curious if architectures got included or not type the command:

 file path of the universalLib.a

or

lipo -info path of the universalLib.a

NOTE : Don’t connect iPhone or iPad while generating .a, else you may get only slice of that architecture. eg. If you connect iPhone 6 then you will only get arm64 bit slice of .a file.

One thought on “Universal or Fat static library

Leave a comment