"Simple checks and actionable tips that we used at Kristal.AI to reduce app size by 65% (especially Android app size)."We, at Kristal.AI, recently migrated our native app to react-native. Consequently, the Android APK size shot up from ~10MB to ~50MB. Initially, we accepted the large size as a side-effect of this framework. However, two things prompted us to act.
For every 6 MB increase to an APKโs size, we see a decrease in the install conversion rate of 1%.
The removal of 10 MB from an appโs APK size in emerging markets correlates with an increase in install conversion rate by ~2.5%.
I will now go into the steps that we took to reduce app size and managed to bring it down by nearly 65%. The first two steps are applicable only for Android. The final step consists of general checks which you should do every once in a while for both Android and iOS Apps.
Before we undertook this activity of app size reduction, we were distributing our app by compiling and uploading APKs. Oh man! It was frustrating to learn about App Bundles. We couldnโt believe that we were still using fat, bloated APKs! APKs are built to run on all device types and therefore contain a lot of extra code which was being sent to users without any purpose.An Android App Bundle (.aab) contains all this extra code too. But the key difference is that when you use an app bundle, you are moving the responsibility of creating APKs to Google. So every time someone downloads the app, Google will automatically generate an APK specifically tailored for the device devoid of any unnecessary code. This means all that extra code is stripped away and the download size for the user comes down significantly. In essence, moving to app bundle consists of the following steps:
./gradlew bundleRelease
In your source folder navigate to android/app/build.gradle and add the following lines
def enableProguardInReleaseBuilds = true
Proguard optimizes and shrinks down your Java bytecode, thereby reducing app size.
def enableSeparateBuildPerCPUArchitecture = true
There are several CPU architectures that Android supports (armebi and x86 for example). By creating separate builds for each, we are able to cut down on app size. As we are using App Bundle, we donโt have to handle the separate APKs and Google will do the heavy lifting for us.
Finally, I will mention some general steps that can help keep both android and iOS app sizes in check. These simple steps will also boost performance by making the bundle loading step faster:
Before: Download size approaching 50MB and installed size has breached 100MB
As is evident from the numbers, these steps have given us good results. Most of the reduction has come from the move to Android App Bundle. But the general steps mentioned will prevent the size from creeping up again over time and will also speed up JS bundle loading.While we are currently satisfied with these numbers, there are a few more things that we plan to do to further optimize app size. They include but are not limited to: using react-native-bundle-visualizer to further optimize npm packages, trying to completely eliminate certain libraries like testing libraries from production builds and enabling hermes which improves JS performance.
By
Kshitij Gangal
May 28, 2021
Liked it?
Share it with your friends & colleagues!
A fully digital onboarding process that can be completed within 15 minutes.
No more voluminous paperwork and queuing!
I understand the financial products and would want to proceed with investing without a financial guide
Proceed