shrinking large APK sizes

642 views
Skip to first unread message

Brian MacDiarmuide

unread,
May 14, 2014, 10:41:34 AM5/14/14
to kivy-...@googlegroups.com
I'm sure the reason behind the large apk sizes from kivy/buildozer is an issue that's been looked into time and again, as the smallest
apk I have generated so far, from very simply games with very few images etc. has been around 7mb. I just created a version of breakout
that includes no images, and several mp3 files, which came to 14mb! That to me seems huge considering it's such a simple game and 
there are literally 4 mp3 files, three of which are seconds long, and the other a full track. 
   So, I googled shrinking apk sizes and came across this page which mentions Proguard which it claims 'shrinks' the code, seemingly through
some form of obfuscation(or along side of perhaps). I was wondering if there was a tool like this for python that anyone knows of, and whether
it would even be possible to use such a tool along with kivy and/or buildozer? Are there any other tips anyone could give me on minimizing apk
sizes? Also, is this something that is likely to change in kivys' future? 

I have never made android apps/games or apks with anything other than kivy/buildozer, so perhaps these sizes aren't unreasonable, but to me
it seems most apps are at least under 4mb. 

ZenCODE

unread,
May 26, 2014, 10:05:12 AM5/26/14
to kivy-...@googlegroups.com
Hi there

This does not say a lot, but captures the essence: https://groups.google.com/forum/#!searchin/kivy-users/apk$20size/kivy-users/GnWWkC9sTwQ/fdD6dt63XKQJ

Basically, Kivy ships with the the whole python interpreter plus a bunch of modules/libraries Kivy/Python needs to run. Quite a bit of work has been done to make it this small, so I doubt it's possible to make it much smaller. It is largish for an Android app, but if your end product ships with Mp3's, images and other large resources, they will quickly overtake this.

So, it's one of the compromises you make for having your code ship with a complete framework that runs anywhere. If Kivy removed too much, it would have to use the Javap API's for functionality and then break Kivy's cross platform premise. And if you make you app good enough, I doubt 6-7MB is really going to stop many people downloading it...:-)

Cheers

knappador

unread,
May 26, 2014, 8:32:03 PM5/26/14
to kivy-...@googlegroups.com
It's possible to make APK's under 4MB.  I'm working on a much more restricted set of default packages here:

https://github.com/knappador/kivy-android-nativer

First things first, try building with my blacklist.  If you want to work together, Kivy imports too many of it's own modules by default, preventing us from blacklisting them and even taking out the objects from the resulting Cython binaries.  Making these imports lazy/conditional and try-catch protected will quickly get us a smaller Kivy.

To get things really small, you want to strip out the kivy artwork, default fonts, and tons of extraneous widgets that you might not be importing.  You can also compile with -Os flag everywhere by editing distribute.sh.  We're working on it =)

To really, really win at this, we need to be using snakefood or a similar import tracking system (roll our own to strip kivy modules smartely?) to automate the blacklist/whitelist project for the larger libs, like Kivy itself.

I can regularly build APK's at the 4.7MB size and that's without all of my tricks in one place.  Putting all my tricks into one place and using conditional imports to really put Kivy on a diet is next.  We're looking at potentially less than 3MB if I do everything in one place.  The nice thing about binaries is that they actually do compress more than you would expect due to the large amount of identical instructions used, ie JAL, JAS, JNE, JE etc.  50% compression is not unseen and the binaries aren't big to begin with when using Thumb-2 and -Os.

There are a lot of details to this that need to be automated.  Feel free to pull request my stuff or create a feature branch on Kivy and let me know about it.

knappador

unread,
May 26, 2014, 8:38:21 PM5/26/14
to kivy-...@googlegroups.com
https://groups.google.com/forum/#!topic/kivy-users/hY5UofLb_MQ

More details on shrinking P4A/Kivy.

Just out of curiousity, wish someone would build a minimum P4A app using these settings without Kivy and see where we end up.  This is the minimum size that frameworks like Corona would compare to.

ZenCODE

unread,
May 27, 2014, 2:30:54 AM5/27/14
to kivy-...@googlegroups.com
Nice. Thanks knappador. And I'm sure that includes stripping out distutils ;-)
Reply all
Reply to author
Forward
0 new messages