I'm a Java programmer.
I included an open source C library, say A, into my android project to do some native work through function F1. Function F1 works well but the shared library compiled by A is, let's say, 5M in size. That means my final APK will increase about 5M which is big.
My question is, how can I shrink the shared library to only include functions that I need? Or at least remove most functions that I don't need? Is there any tools that can achieve this?
Update 1:
@Employed Russian has answered big part of the question above, which is by 'strip' tool.
My further question is, is there any tools can achieve things like what ProGuard does to Java, that is completely removing code I didn't call?
Function F1 works well but the shared library compiled by A is, let's say, 5M in size.
It is exceedingly likely that your shared library contains debug info, which can easily be 80% of the size, and which you don't actually need. Most open-source libraries build with -O2 -g
flags, and the -g
is what contributes to the size of the final library.
To get a library without debug info, you run strip
, like so:
cp libA.so libA.so.orig # keep original in case you need to debug it later
strip -g libA.so
Now compare sizes of libA.so
and libA.so.orig
. Chances are, libA.so
will be significantly smaller.
You should be able to squeeze libA.so
even more, by running strip libA.so
. This removes all symbols, not just debugging symbols, but makes it harder to debug any crashes related to libA.so
. However, since you kept original full-debug copy, that shouldn't be a big problem.
Since you said the library is open source.. Just track the function implementation and along with classes it depends and recompile your own smaller version of the library.
Trust me this sound hard but will actually save you more time than playing with compiled c/c++ code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With