After including com.ensody.kompressor:kompressor-brotli-ktor the release APK size of my app went from 3.1 MB to 7.4 MB 🥲
The most impacting thing is libbrotlienc.so (3 MB, literally as big as a whole music streaming application), which I don't actually need, as I only need Brotli to decompress payloads returned by the server.
So, I simply attempted to strip it off from the APK:
android {
packaging {
resources.excludes.add("META-INF/nativebuild.json") // also needed but irrelevant for this issue
jniLibs.excludes.add("lib/arm64-v8a/libbrotlienc.so")
}
}
But this caused the following error:
Rejecting re-init on previously-failed class java.lang.Class<com.ensody.kompressor.brotli.BrotliWrapper>: java.lang.UnsatisfiedLinkError: dlopen failed: library "libbrotlienc.so" not found
(removed irrelevant lines)
at void com.ensody.nativebuilds.loader.NativeBuildsJvmLoader.load(com.ensody.nativebuilds.loader.NativeBuildsJvmLib) (NativeBuildsJvmLoader.kt:46)
at void com.ensody.kompressor.brotli.BrotliWrapper.<clinit>() (BrotliWrapper.kt:24)
at void com.ensody.kompressor.brotli.BrotliDecompressorImpl.<init>() (BrotliDecompressor.jvm.kt:11)
at com.ensody.kompressor.core.SliceTransform com.ensody.kompressor.brotli.BrotliDecompressor_jvmKt.BrotliDecompressor() (BrotliDecompressor.jvm.kt:8)
In other words, BrotliDecompressor explicitly loads libbrotlienc.so, which not needed.
Also confirmed by code:
|
init { |
|
NativeBuildsJvmLoader.load(NativeBuildsJvmLibBrotlicommon) |
|
NativeBuildsJvmLoader.load(NativeBuildsJvmLibBrotlidec) |
|
NativeBuildsJvmLoader.load(NativeBuildsJvmLibBrotlienc) |
|
NativeBuildsJvmLoader.load(this) |
|
} |
I would really like to not include a native library I'm not using. Would be possible to load native libraries only if needed?
After including
com.ensody.kompressor:kompressor-brotli-ktorthe release APK size of my app went from 3.1 MB to 7.4 MB 🥲The most impacting thing is
libbrotlienc.so(3 MB, literally as big as a whole music streaming application), which I don't actually need, as I only need Brotli to decompress payloads returned by the server.So, I simply attempted to strip it off from the APK:
But this caused the following error:
In other words,
BrotliDecompressorexplicitly loadslibbrotlienc.so, which not needed.Also confirmed by code:
Kompressor/kompressor-brotli--nativelib/src/jvmCommonMain/kotlin/com/ensody/kompressor/brotli/BrotliWrapper.kt
Lines 21 to 26 in 4ed262a
I would really like to not include a native library I'm not using. Would be possible to load native libraries only if needed?