Arslan Anwar
Arslan Anwar

Reputation: 18746

Reduce size of APK when including .so files

I am using a 3rd party API for camera library that is using ffmpeg frame recorder and .so files along with javacv.

I am also using a 3rd party library for extracting meta data out from a video which also has some .so files

When i merged all these files into only one folder "armeabi" my application did not work. So I have to copy all these files to all other folders "armeabi-v7a, mips, x86". Which works perfectly fine but obviously the size of the apk is now too large.

Total size of these file are 20MB per folder. That make 80MB for all folder. My .apk size is 41MB. Please suggest ma what I can do to remove duplicate files/folders or reduce .apk size.

Why I need all these folders armeabi, armeabi-v7a, mips, x86 enter image description here

.so files in folder enter image description here

Upvotes: 1

Views: 2935

Answers (2)

jww
jww

Reputation: 102286

I think alpinescrambler's answer is probably most applicable, but here's some things you can do even if you follow his suggestion of multiple APKs.

First, you can omit armeabi-v7a since it can be satisfied with armeabi.

Second, build your shared object and the ffmpeg shared object with -Os.

Third, build your shared object and the ffmpeg shared object with -ffunction-sections. Later, the unused functions can be removed. In fact, here's a typical compile line for armeabi (for one of my projects):

arm-linux-androideabi-g++ -MMD -MP -MF …/MyProj/obj/local/armeabi/objs/prng/libprng.o.d -fpic 
-ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te 
-mtune=xscale -msoft-float -mthumb -Os -g -DNDEBUG -fomit-frame-pointer 
-fno-strict-aliasing -finline-limit=64 -I/opt/android-ndk-r9/sources/cxx-stl/stlport/stlport 
-I/opt/android-ndk-r9/sources/cxx-stl/system/include -I/usr/local/cryptopp/android-armeabi/include 
-I…/MyProj/jni -DANDROID  -Wa,--noexecstack -frtti -fexceptions -I/opt/android-ndk-r9/platforms
/android-14/arch-arm/usr/include -c  …/MyProj/jni/libprng.cpp 
-o …/MyProj/obj/local/armeabi/objs/prng/libprng.o 

Fourth, build your shared object and the ffmpeg shared object with 16-bit thumb instructions with -mthumb (and not 32-bit arm instructions with -marm).

Fifth, utilize __attribute__ ((visibility ("hidden"))) in your shared object and the ffmpeg shared object. It will keep the export tables small. It will also result in quicker load times.

Sixth, build your shared object and the ffmpeg shared object with -Wl,--exclude-libs,ALL to ensure you are not re-exporting other library functions.

Seventh, run arm-linux-androideabi-strip --strip-unneeded on your shared object and the ffmpeg shared object. This is possible because you compiled with -ffunction-sections.

Eigth, run arm-linux-androideabi-strip --strip-all on your shared object and the ffmpeg shared object.


Also, do you even need MIPS? I have not been able to locate a tablet. My attempts to locate one have been met with "closed, off topic".

Upvotes: 2

alpinescrambler
alpinescrambler

Reputation: 1954

If you want to support multiple architectures, then you need these multiple folders. However, there is a way tor reduce your APK size(s) by deploying multiple APKS, i.e. specific APK for each CPU type.

See these links:

https://software.intel.com/en-us/android/articles/google-play-supports-cpu-architecture-filtering-for-multiple-apk

http://developer.android.com/google/play/publishing/multiple-apks.html

Upvotes: 3

Related Questions