Google I/O 2017

Best practice to reduce APK size announced in Google I/O 2017 Part 2

Shayan Tabatabaee
4 min readMay 25, 2017

This is the part 2 of the article series. In part 1 we understand APK size analyzer and ProGuard. in this part we will implement other methods to reduce app size according to Google I/O session.

Check part 1 here :

Let’s get started.

Build multiple APK

As saw in the resource folder, when we were looking for the APK analyzer, we have drawables for difference screen density. The android ecosystem is diverse for different displays and different CPUs.

You can split your build across these dimension, and then upload multiple APKs to Play Store. For example you can see how much the application size reduced in XXHDPI screen’s build.

Use vector drawable

This is another way to reduce the amount of size you carry with your assets and that’s to use vector drawables instead of PNGs.

One thing to keep in mind with vectors is that they can increase your RAM and CPU load, especially when you first start up the application so it is better to do a bit of performance test.

Use vector drawables have some benefits in comparison to multi APKs because it simplify your QA process and upload one APK.

Exclude sparse translation

In this section we want to make ARSC file 2X smaller with one line of code. If you see inside the ARSC file you will notice that some strings only appear in English but other strings have many translations for them. Because the Support Library folks went out of their way to localize your strings. Multi language app is a good way to reach out more users, but half-translated apps can make a poor user experience. Empty spaces in ARSC file actually use bytes in our ARSC file by indicating no entries. We can simply get rid of this unused languages by adding one line to grade file that we only want english strings.

resConfigs “en”

Use downloadable fonts

Fonts are a source of bloat for apps, and they are heavy files. But you need them because you need it for UX. several apps are bundling the same fonts, and you’re duplicating them in your device. You typically bundled fonts in your app and that causes your APK size to increase.

In downloadable fonts use a concept of a font provider. Font provider is a separate app that its own mission to fetch fonts, cache them, and serve them when needed.

All apps should contact to font provider via the font’s contract APIs. This means we have one copy of the font that all apps using the same font.

By doing this we save memory, because we are only loading the font once and also saving the APK size. This is available in Android Studio 3.

Android Asset Packaging Tool 2

This is the part of the build system that process and package all your resources into the APK. The AAPT 2 is embedded by default in android studio 3.0 But you can enable this in canary version b adding this line to cradle properties.

android.enable Aapt2 = true

Thanks for reading. To help others please click ❤ to recommend this article if you found it helpful.

--

--