PrimaryChicken
PrimaryChicken

Reputation: 973

iOS merge several framework into one

After watching the WWDC 2016 video optimizing App Startup time, Apple suggested developer can merge several frameworks (dynamic library not static) into one to improve the app cold start time. https://developer.apple.com/videos/play/wwdc2016/406/

So I downloaded a dummy project here:

https://github.com/stepanhruda/dyld-image-loading-performance

And try to merge two frameworks into one using the following command:

libtool -static -o new.framework SwiftyJSON.framework Shimmer.framework

And the console returns

error:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't map file: SwiftyJSON.framework (Invalid argument)`

error:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't map file: Shimmer.framework (Invalid argument)

So my question is how to merge several framework into one? Can we use libtool to do it and how to do it? Many thanks.

Upvotes: 24

Views: 10505

Answers (3)

Siddharth Gupta
Siddharth Gupta

Reputation: 897

If you're trying to merge frameworks created by cocoapods, you can use the pod-merge plugin: https://github.com/grab/cocoapods-pod-merge

Upvotes: 2

Ted
Ted

Reputation: 23746

For dynamic frameworks lipo -create path/yourFramework1 path/yourFramework2 -output path/yourFramework

For .a libraries

  • where sim/lib.a contains i386
  • where dev/lib.a contains armv7

lipo -create '/sim/lib.a' '/dev/lib.a' -output 'lib.a'

output contains i386 and armv7

Upvotes: 4

PrimaryChicken
PrimaryChicken

Reputation: 973

I can combine two frameworks (static library only) into one using

libtool -static -o new.framework SwiftJSON.framework/SwiftJSON Shimmer.framework/Shimmer

The script from this github maybe helpful https://gist.github.com/evands/8ba4f227b00ae14a9303

P.S. Merging static library does not reduce the cold start time

Upvotes: 2

Related Questions