DEV Community

Cover image for Reduce APK size in React Native
Ritesh Shukla
Ritesh Shukla

Posted on

Reduce APK size in React Native

Reduce App Size in React Native:

We all have faced problems related to the size of the built apk in React-Native. The size of the apk is usually very high . This eats up a lot of space in the phone's storage. Let's look at a few methods to avoid large apk size in the final bundle.

Remove Codes and assets.

One simple method is to use light-weight assets. Use jpg instead of a high quality png image (if not required). Use vector icons(Prefer React Native Vector icons). Optimize your image files using some tools like tinypng.com. Also, remove unused codes and JS files.

Prefer light-weight node modules

You can use alternate node modules to reduce the size of APK by finding the weight of your current node modules by the use of cost-of-modules(npm install -g cost-of-modules).If any module is of high cost, replace it with less cost alternatives.
Image description

Compress Java Bytecode

Navigate to android/app/build.gradle .Set the def enableProguardInReleaseBuilds to true.This would enable Proguard to compress the Java ByteCode leading to reduction in the apk size.

Separate APK for separate CPU architecture

Navigate to android/app/build.gradle .Set the def enableSeperateBuildPerCPUArchitecture to true.This would build different apks for different CPU architecture(x86 and arm).Upon publishing on playstore, playstore will automatically deliver required apks according to the phone's CPU Architecture.
Image description

Top comments (0)