How to reduce React Native App size by 70–85% using these simple methods
I recently develop a Mobile app called Candlestick Patterns for Stocks, It is a mobile learning app for traders to enhance their trading entry and exit points using technical candlestick patterns. As I finished my app I instantly created a new app in my Google Play Console and put some descriptions, answers some questions, and then finally build my app for production using Android Studio.
After finishing building my app I looked at the APK build and instantly noticed the app size which was 31MB. Google play console reports that more than 16.3 MB of app size can be a deal-breaker for users who have limited data plans or little to no available disk space and have to choose which apps to keep or uninstall. To cater to a potential market segment who have a limited data plan, let’s reduce our React Native App size as much as possible, Here’s how:
#1 Create a separate APK for each CPU
By default, the generated APK has the native code for both x86 and ARMv7a CPU architectures. This makes it easier to share APKs that run on almost all Android devices. However, this has the downside that there will be some unused native code on any device, leading to unnecessarily bigger APKs.
You can create an APK for each CPU by changing the following line in android/app/build.gradle:
def enableSeparateBuildPerCPUArchitecture = true
#2 Enable Proguard
Proguard is a tool that can slightly reduce the size of the APK. To enable Proguard, change the following line in android/app/build.gradle:
def enableProguardInReleaseBuilds = true
After enabling Proguard you can now enable minifyEnabled and shrinkResources in your build release to optimize your code. Edit android/app/build.gradle to enable.
#3 Optimize Images
You can compress your images size by 50–80% using tinyJPG. Using this method I was able to reduce my asset size by 50%. When you optimize your project images, it would not only reduce your app APK size but will also increase your app loading speed.
Using the steps above I was able to reduce my App APK size from 31MB to 6.7MB. The methods mentioned above are also applicable for generating Android App Bundles(Abb) the new publishing format for the google play console. Abb is generally bigger in size, it already contains APK’s for distribution for different device configurations and languages. And it ensures that the download size for end-user will be less.