Reputation: 71
It takes 8-10 secs for my JNI .so libray to pack in apk with apkbuilder. The library is about 8MB and written in C++ mainly.
To clarify the problem I have done following tests.
1) Other .so library
I replaced .so library with other .so which is about 10MB and written in C mostly. Surprisingly, it takes 1.5 secs with the new .so which is also a JNI library for same CPU architecture.
2) Dummy file
I put a dummy file with a name of xxx.so in my libs/armabi-v7a directory. It takes 1 secs.
3) Different CPU architecture
All my .so libraries for arm/x86/mips takes 8-10 secs.
4) Forged
I edited my .so library with a hex editor in random places with random values. It also takes 8-10 secs.
Why only my .so library takes so long to be packed into apk with apkbuilder? Is there any way to speedup this process for my .so library?
Upvotes: 0
Views: 185
Reputation: 71
I have found that the most of time was spent by ZipOutputStream to compress the .so file.
Android ApkBuilder uses the compression level 9 which has the highest compression but the slowest performance. If I change this level to 3, the whole performance improves dramatically with a little compression ratio loss.
You can change this level fixing the sdklib source code. In SignedjarBuilder.java (com.android.sdklib.internal.build), find 'mOutputJar.setLevel' and change the level you want. Then create sdklib.jar and copy this to your Android SDK directory (android_sdk/tools/lib)
You can download the source code here: https://android.googlesource.com/platform/tools/base/+/master/sdklib/src/main/java/com/android/sdklib/build/
Upvotes: 0
Reputation: 5340
An APK file is essentially just a ZIP file and the .so files are added to it without any APK-specific processing. So the most likely cause is that apkbuilder tries to deflate your .so file which takes some time while deeming the other .so file uncompressable and just storing it.
AFAICS the only way to speed this up is to change apkbuilder source to always store and not deflate .so files.
Upvotes: 2