:wave: Since using KMM to compile a shared module...
# kotlin-native
m
👋 Since using KMM to compile a shared module, my XCFramework size has ballooned from 13 to 99 MB. I know that on the Android side we have R8 and progaurd to minify and remove unused code from dependencies. Does anything like that exist on the iOS/Mac side? Or what tools are available to prune the size of the KMM objc frameworks?
h
Didn't test it, but I think, Xcode is able to optimize it, the xcframework itself contains often multiple architectures and the bitcode, which is used to reduce its size. You can measure it by creating an archive in Xcode in the organizer window. https://help.apple.com/xcode/mac/current/#/devbbdc5ce4f
m
Right, I think thats different though. More about what the AppStore does to minimize App size when downloaded (Before app thinning AppStore would download all architecture slices even ones not used by your device). The destination for what I’m building is a Cocoapods framework though, so app thinning wouldn’t apply.
What I’m looking for is something within the Kotlin compilation process that can do this:
Code shrinking (also known as tree shaking), is the process of removing code that R8 determines is not required at runtime. This process can greatly reduce your app’s size if, for example, your app includes many library dependencies but utilizes only a small part of their functionality.
h
Okay, I don't use Cocoapods. But I tested the KMM xcframework: From 33 MB release (arm64 iOS and arm64 simulator) down to 9.9 mb App Store app
BTW the debug framework was 56 MB, for this demo app: https://github.com/hfhbd/ComposeTodo 😄
m
Ya, I wonder if it is Ktor that is kind of massive and includes a lot of stuff that really explodes the size
r
@kpgalligan recently talked about this: https://www.droidcon.com/2022/08/01/sdk-design-and-publishing-for-kotlin-multiplatform-mobile-2/ (around 34:30). TLDR: you should try to limit the exposed API to reduce the size of the generated adapters.
h
And limit exported dependencies and disable transitive export.
m
awesome I’ll check this out!