tldr; Swift runtime on Android is big, can it be smaller?
First, many thanks to @Finagolfin and @v.gorlov as well as comments from others on this thread! Without it, we would not be able to do cross-platform work in Swift (currently deploying to macOS, Windows, Linux, iOS, and Android). I work with @dstoker-cricut who asked questions above to get that done.
We have a cross-platform geometry library written in Swift that uses only Foundation (lightly), SwiftNumerics, and ArgumentParser or SwiftProtobuf for interfacing.
Has there been any work on slimming down the requirements for a deployed Android GUI application using a Swift library? Our Android clients are experiencing a doubling of the size of their app when using the library.
Currently on Android, we access the library via a pair of Swift functions declared with @_cdecl
taking either a command string or Protobuf command payload. To do that, we need to carry 19 shared object files around, totaling 78MB for the x86_64 arch alone. When stripped of debug symbols (using strip -g), they still weigh in at 58MB. The files are:
Library | Size (bytes) |
---|---|
libicudataswift.so | 30204656 |
libFoundation.so | 7814560 |
libswiftCore.so | 5710176 |
libicui18nswift.so | 4115896 |
libcrypto.so | 2936856 |
libicuucswift.so | 2525416 |
libFoundationNetworking.so | 1171920 |
libxml2.so | 1098464 |
libc++_shared.so | 989800 |
libswiftRemoteMirror.so | 817512 |
libssl.so | 601968 |
libdispatch.so | 364848 |
libcurl.so | 350528 |
libFoundationXML.so | 329504 |
libicutuswift.so | 322568 |
libswiftSwiftOnoneSupport.so | 282344 |
libswiftDispatch.so | 218376 |
libswiftGlibc.so | 74616 |
libBlocksRuntime.so | 10424 |
Around 56% of the size comes from the 4 International Components for Unicode (ICU) libs, 27% from other direct Swift runtime libs (including libxml2), and the remaining 17% from other dependencies.
We've tried all the tricks Google recommends on 앱 크기 줄이기 | Android 개발자 | Android Developers like arm-eabi-strip
, leaving native libs compressed with extractNativeLibs
in the manifest, and applying resource size tricks with shrink-resources
. These help further, but the size of the Swift libraries just makes this hard.
What can be done to slim them down further? Using the Android-embedded ICU somehow instead of these libs is the clear #1 option, but a bit out of my league. Any help there would be greatly appreciated! Are others seeing these files at the same sizes? Any other thoughts to reduce their size?