15 ms·
APK Golf: Reducing an Android APK's Size by 99.99%
- deleted 9y ago[deleted]
- aw4y 9y agoremoving support library, layouts...please.
- Munksgaard 9y agoEither I'm whooshing some sarcasm, or you're missing the point.
- Aissen 9y agoIndeed. I thought the fact that he removed the Launcher Intent would be of more concern.
- HillaryBriss 9y agoyeah, i had the same thought. this post cannot be taken as practical advice. interesting to see just how much bloat an apk contains though.
- ocdtrekkie 9y agoBack when they introduced them, I was pretty strongly opposed, and you can see the effect. We now have half the Android UI shoved in each app package. Back when I started using Android, apps were rarely over 1 MB in size. Now, with no real improvement in functionality, apps are regularly over 50 MB.
- s73ver_ 9y agoUnfortunately, that seems to be the only way to get a reasonable baseline, given that Google has no way to actually update Android devices.
- Aissen 9y agoNo, the libs could be shared between apps, with at most one per API level, and shipped through the Play Store. If you want your app to work without Play Store, bundle the libs like today.
- kbenson 9y agoSo, basically the Visual C++ Redistributable[1] but for Android? Seems to work well for Windows, from what I can tell. 1: https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B
- s73ver_ 9y agoThey already have one distributed through the Play Store. That's the proprietary bits. The Support libs are open source, they can work without the Play Store, and different apps can have different versions of it.
- Aissen 9y agoYes, and they can ship a shared version of the open source libs (like the system webview). And as I specified, with one per API level (different versions). Maybe that would force them to have better QA of those libs as well.
- brink 9y agoKinda cool.. though it also seems pointless or hollow of meaning? "Let's make a package as small as possible while removing everything. Our next feat will be the world's most empty room." What's more interesting to me is when the app is extremely small, yet still does something useful.
- jbergstroem 9y agoWhat made me post the link was that it – disregarding its debatable pointlessness – showed a diverse set of methods and tools that are useful in android packaging.
- craftyguy 9y ago> Our next feat will be the world's most empty room Actually, this is incredibly hard to do, since it would require creating a near-perfect vacuum.
- pbhjpbhj 9y agoMy room is doughnut shaped and resides in the relative space between a hydrogen atoms proton and electron ... do I win?
- craftyguy 9y agopix or it didn't happen
- tener 9y agoYou do, but a little formality first: can you please prove, definitely, the size of the proton? There are conflicting opinions floating around...
- vesinisa 9y agoI measured the size of your room and it seems to have collapsed.
- hasenj 9y agoBeware of all the photons passing by.
- freecodyx 9y agoDo 50 push-ups while gradle syncs. touche
- kbenson 9y agoThis is code golf. I mention that because apparently some people are missing the point, which is purely to get the smallest size. This isn't directly applicable to most work you might do, but like many exercises that explore the extremes, useful knowledge can be learned from the attempt. In a similar vein, there's a classic article on creating a tiny ELF executable.[1] 1: http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html http://www.muppetlabs.com/~breadbox/software/tiny/teensy.htm...
- petercooper 9y agoAlso, building a 1KB Docker container: https://blog.quickmediasolutions.com/2017/09/28/a-1-kb-docker-container.html https://blog.quickmediasolutions.com/2017/09/28/a-1-kb-docke...
- rorosaurus 9y agoAlso, The Infinitely Profitable Program: https://web.archive.org/web/20160304014157/http://peetm.com/blog/?p=55 https://web.archive.org/web/20160304014157/http://peetm.com/...
- alanbernstein 9y agoJeez, that article ends like The Lord of the Rings movies...
- warent 9y agoSo... it's a signed binary manifest file? That's hilarious and fascinating
- n-gauge 9y agoandroid:allowBackup="true" But I may want my app to be installed to the sd storage. On a separate note: can we not recalc the apk v1 signatures via a javascript crypto function?
- yjftsjthsd-h 9y agoWhat, is it too big for your internal storage? ;)
- fractalwrench 9y agoAuthor here - happy to answer any questions anybody might have. Also sorry for the shameless plug, but the startup I work for is currently hiring: https://www.bugsnag.com/jobs/ https://www.bugsnag.com/jobs/
- markcerqueira 9y agoAre you guys based out of Bath, UK? Visited it this past summer and loved it! :)
- fractalwrench 9y agoOur main HQ is in San Fransisco, but we also have an office in Bath as both the founders went to university there (as did I). It's a really great city to see on a good Summer's day - the Roman Baths are well worth a visit.
- HillaryBriss 9y agothank you for an interesting/educational article! in the section named "Where we’re going, we don’t need IDEs" the sequence of commands creates a file named app.zip at one point: zip -r app app.zip but app.zip doesn't seem to be used later. am i missing something or should that be: zip -r app app-release-unsigned.apk
- fractalwrench 9y agoYep, that's a typo, thanks for letting me know.
- citrin_ru 9y agoIt is possible to get zip archive with slightly better compression rate using 7zip instead zip command: 7za a -tzip -mpass=15 -mfb=257 -ba -bd app.zip app
- cordite 9y agoWhere is the screenshot of the app at the end?
- saagarjha 9y agoI'd like to see how this is done on iOS, since the OS is much pickier about what it will let you install.
- netsec_burn 9y agoInfo on further reduction: https://github.com/fractalwrench/ApkGolf/issues/2 https://github.com/fractalwrench/ApkGolf/issues/2
- mike_kamau 9y agoBeautiful. Someone should do the same for all the Javascript-framework-driven web apps clogging the web.
- theandrewbailey 9y ago> Beautiful. Our APK weighs in at approximately 1.5Mb. WTF? This Hello World app is 1.5 MB, but MS Paint, a program with much richer functionality, is not even a third of that! I know that MS Paint is ancient, but if it takes 1.5 MB by default to put text on a screen, multiple levels of something have failed, especially when it can squeeze down to <100 KB without too much trouble.
- kogus 9y agoI don't necessarily disagree, but MS Paint on my Windows 10 machine weighs in at 6.5Mb. Notepad++ is just 2.5Mb though. And the Windows Media Player is just 163k.
- drak0n1c 9y agoAren't there also dll dependencies that allow modern Windows apps to be so small?
- kogus 9y agoOften yes. Sometimes not. I don't know about the specific ones I mentioned. You can definitely build a self-contained WinForms app in under a meg, though.
- georgemcbay 9y agoYes. The Windows Media Player referenced is a perfect example, since it is basically just a shell app where all the UI functionality is pulled in from plugins and all of the codec support is handled through external codec libraries. There is definitely a bit of bloat when it comes to Android apps that use the support libraries, as the OP article mentions, but the benefit you get for that bloat is worth it if you're writing full featured real-world applications. (The support libs make it easy to support newer Android features backward compatibly to very old handsets).
- duiker101 9y agoThing is, space and bandwidth are way cheaper now compared to the age of MS Paint. 1Mb, 10Mb, even 40 or 50 don't do much difference to most users but they can make things easier to develop/maintain/whatever. Which in the end could save a lot of money to a company.
- ggm 9y agoIf you depend on shared library or external state, then in the zen sense, it cannot be "whole" in "one" (sorry)
- nneonneo 9y agoI got slightly nerd-sniped on this and started optimizing (along with a few others)...we’re under 1K now (922 bytes from 1757 bytes) and still going. https://github.com/fractalwrench/ApkGolf/pull/4 https://github.com/fractalwrench/ApkGolf/pull/4
- dheera 9y ago1.5 MB for an app that does nothing. 1.5 million bytes for nothing. How inefficient we are these days. I really wish it were as simple as this: $ cat > myapp.aml <!doctype android> <head><title>My App</title></head> <app activity="MainActivity.java"></app> ^D $ cat > MainActivity.java import android; class MainActivity extends Activity { void main() { android.toast("hello world"); } } ^D $ android compile myapp.aml Could not find a keystore in your home directory. Would you like me to create one for you (y/n): y Enter a keystore password: ******** Confirm password: ******** Thanks! Compiling Java code ... done! Zipping it up ... done! Signing ... done! Byte-aligning ... done! Wrote myapp.apk. You're ready to upload to the Play Store! $ But no. We must over-complicate things. AppCompatActivity, manifestations of manifests, layers upon layers of gradle BS, keystores, lots of stackoverflow lookups just to deal with byte aligning, signing, etc. And then Android Studio updates itself, breaking your entire project's 79+ files that for a blank app. What has the world come to?
- maxsilver 9y agoI totally agree with you. But as an Android developer, I know why we won't get to this... What does this app do on phones? On tablets? On laptops? Where is the header bar (the original has one, yours doesn't). What color is it? What font? What placement? What about users who don't read English? What about users who's languages don't fit in ASCII. What about users who's languages aren't read left-to-right. How should the header bar even be drawn? What about devices that can't draw the header bar as defined? What about devices that were invented before header bars even existed? What about devices whos OEMs fundamentally redefined what 'drawing' even means. MainActivity.java does what? Is it Java 6? 7? 8?. Which of the 26 'Activity' classes are you extending from, and how do you know it exists on the device? How do you know it behaves identically? The .toast method does what? For which phones? On which API release? How long or short should the Toast display for? Your keysigning the app? Which method of keysigning are you using (old or new, they aren't the same). Who's authoritative for the signing (yourself, or Google Play. Those aren't the same either.) The sample app, with it's 1.5 million wasted bytes that 'do nothing' handles those problems. It's easy to say "I saved 5k bytes by dropping RTL" but... you dropped all RTL language support. People use that stuff. The example steals a pre-made asset from system resources to save space, which is clever until system resources you need aren't there, which happens in the real world. AppCompat is heavy, but it isn't bytes-for-nothing. Some poor souls at Google waste a lot of time making sure developers get a large library of useful layouts and controls that all mostly-just-work mostly-consistently across a huge spectrum of devices and API releases. No one intentionally sits down and builds over-complicated code by choice (except perhaps Spring). Every layer of the BS here may be annoying and wasteful, but it attempts to solve a real problem a real person had to deal with. I love the simplicity of your example. But I'm not sure I'd want to deal with the consequences of living in that world.