How to make a super small Android application for your website
Surprisingly, a minimum single Activity “Hello World” application compiled in Android Studio would take 2-4 MB. This size is not too much compared to most apps. It is actually in the acceptable range for Lite apps that we checked last time. But this is quite a lot when we think of the amount of functionality we've got. Let’s take a look inside.
A snapshot from the Apkanalyzer shows that almost 2MB go to classes.dex file which contains assembled code. That is 80% of the APK. However, resources such as icons and XMLs contribute more than we expected, too.
Turned out, this is the default Android Studio template that make new Android apps look good from the first touch of Make button. Android Studio added all sizes of icons and convenient resource files to store different values as well as it included bloated dependencies. Three of them provide testing capabilities and others produce rich UI/UX experience: appcompat, material, constraintlayout.
To simplify everything we will make a small demonstrative app for our website. Usually, WebView component serves well for such purposes. It simply renders web pages inside the app. No other buttons, no functionality, we just want to render our website page ASAP, but also keep the app small.
Actually, this is a super simple task. We create a single WebView activity, set our website URL and that’s it! Though we follow a few points to reduce app size:
Single WebView activity
Single icon in vector (works everywhere, saves a lot)
No other resources
No gradle dependencies
Use standard theme (android:theme="@android:style/Theme.NoTitleBar")
Set minifyEnabled and shrinkResourced flags
Possibly set enableJetifier, useAndroidX, buildconfig properties to false
Use R8 full mode optimiser
Thats how we get one of the smallest apps on the Play Store! App bundle for this app weighs just 7.4KB while signed APK is 10.6 KB.
However, at the Play Market Google packs and signs our app for us! Thus, the final APK size becomes 20.6 KB. Yes, Play Store signatures can take half of app size 😄 This size can probably vary depending on the minimum SDK version since Google have to use compatible signature schemes. For example, for the minimum SDK 21 (Android 5.0) Google employs JAR signing first before applying the v2 APK signature scheme.
Google Play also adds some split placeholders for bundling functionality even if we don't split the app. But unfortunately app bundling does not support app versioning for a particular Android version, so there is no way to remove this extra 10KB added by Google Play. But still this app is super small compared to others. Google reports our app's size actually 5MB smaller than the peers' median!