DEV Community

Cover image for Make your React Native app 3x smaller with one simple command
Raaj
Raaj

Posted on

Make your React Native app 3x smaller with one simple command

Ways to Reduce React Native APK Size

  1. - Migrating to React Native from Expo
  2. - Make Changes in android/app/build.gradle
    • 2.1 Set def enableProguardInReleaseBuilds = true
    • 2.2 Set def enableSeparateBuildPerCPUArchitecture = true

1.Migrating to React Native from Expo

I Love everything about Expo except the size of the binaries. Each binary weighs around 25 MB regardless of your app.

So the first thing to do is migrate the existing Expo app to React Native. This is the simplest and coolest method to reduce your APK

To migrate the expo app 1st step to follow is

open your root directory and execute the following the command

expo eject

This will download the required dependencies and build native projects under the ios and android directories.

2.Make Changes in android/app/build.gradle
This is what you have been waiting for, I know.

  • Open up android/app/build.gradle
  • Set def enableProguardInReleaseBuilds = true

this would enable Progaurd to compress the Java Bytecode. This reduces the app size by a tad bit

  • Set def enableSeparateBuildPerCPUArchitecture = true.

Android devices support two major device architectures armebi and x86. By default, RN builds the native libraries for both these architectures into the same apk.

Setting the last function creates two distinct apk in the build folder. You have to upload both of these apk to Play Store and Google would take care of distributing the app to the correct architectures

Using this split generates version numbers for both apk's in the order of 104856 and such. This is auto-generated by the build to avoid version conflicts, so dont freak out (i did).

This split reduced the apk size from around 7mb to 3.5mb for arm and 5mb for x86 respectively.

yeah
so thats how you lose weight. Reducing the size of your app has many added benefits, the best being more users will be willing to download your app. And the app won't consume more space in the user device

Top comments (0)