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:

Initial APK Size before optimizing

#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.

release {
debuggable false
shrinkResources true
minifyEnabled true
useProguard true
setProguardFiles([getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'])
}

#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.

Conclusion

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.

--

--

--

Software developer, working across mobile, web, and custom software development | over 50k views per month | Creator of POSLite www.poslitesoftware.com

Recommended from Medium

Android Studio — Day 04

Round corners animation

Kotlin Static Code Analysis Tool — Ktlint | Perfomatix | Full Stack Engineering Company

How to migrate your DI from Dagger-Android to Hilt?

Creating Rewarded Video Ads in Unity

Cloud Firestore + Android is easy

Nox Player For Mac

Stuck

Making Power-up move Towards Player

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alger Makiputin

Alger Makiputin

Software developer, working across mobile, web, and custom software development | over 50k views per month | Creator of POSLite www.poslitesoftware.com

More from Medium

Best Coding Practices — React Native Edition 2022

Top 5 React Native UI Component Libraries That Developers Should Know

top 5 react native ui component libraries

How to Boost Performance of Your React Native Applications

How to Boost Performance of Your React Native Applications

Top 10 Libraries You Should Know for React Native in 2022