What are best practices to decrease the size of static libraries in objective-c?

前端 未结 1 1052
日久生厌
日久生厌 2021-02-04 08:34

In building an objective-c static library, I noticed that the .a file (fat file from simulator and iPhone) is quite large. In particular, it was originally 5.7mb. I found this p

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 08:46

    In case it's part of your concern, a static library is just the relevant .o files archived together plus some bookkeeping. So a 1.7mb static library — even if the code within it is the entire 1.7mb — won't usually add 1.7mb to your product. The usual rules about dead code stripping will apply.

    Beyond that you can reduce the built size of your code. The following probably isn't a comprehensive list.

    In your target's build settings look for 'Optimization Level'. By switching that to 'Fastest, Smallest -Os' you'll permit the compiler to sacrifice some speed for size.

    Make sure you're building for thumb, the more compact ARM code. Assuming you're using LLVM that means making sure you don't have -mno-thumb anywhere in your project settings.

    Also consider which architectures you want to build for. Apple doesn't allow submission of an app that supports both ARMv6 and the iPhone 5 screen and have dropped ARMv6 support entirely from the latest Xcode. So there's probably no point including that at this point.

    0 讨论(0)
提交回复
热议问题