23

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.

PrimaryChicken
  • 963
  • 1
  • 8
  • 29
  • Did you find a way to merge dynamic frameworks? Even I'm looking for a way to reduce cold startup times by merging dynamic libraries. – vin25 Jan 27 '17 at 07:50
  • @vin25 I couldn't find a way to merge dynamic frameworks, but I think you can use more static libraries. – PrimaryChicken Jan 31 '17 at 12:25

3 Answers3

4

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

Ted
  • 22,696
  • 11
  • 95
  • 109
2

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

PrimaryChicken
  • 963
  • 1
  • 8
  • 29
  • That creates an output of `new.framework` for me, but its not usable. I cannot cd into the framework either. Am I missing something? To be more clear, the output is of Kind:Framework (from Get Info) – Dunes Buggy Jan 09 '19 at 18:32
  • P.S. Merging static library does not reduce the cold start time so what's an advantage merging frameworks into one? – ihsan_husnul Feb 27 '19 at 02:32
  • @ihsan_husnul if you are using too many dynamic libraries into an iOS project, it will increase the app launch time (cold start time). So Apple suggested us to merge dynamic libraries. – PrimaryChicken Mar 10 '19 at 09:53
  • Sorry @PrimaryChicken, could you clarify your response to @ihsan_husnul? What is the benefit of merging multiple static libraries into 1, if it doesn't reduce start time? Is there an effect on build time? If not, what is it useful for? My understanding is typically, by merging libraries or frameworks, we are either trying to reduce the launch time, the build time, or both. Does merging static libraries have any effect on build time? I would guess no, since the merge only occurs after the static libraries are built? – jjjjjjjj Oct 23 '21 at 05:12
2

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

Siddharth Gupta
  • 897
  • 5
  • 20