'React Native Android App size is much big

I have developing apps for customers which can be run smoothly on their devices.My current app size is 5 MB. Now, I want to change technology to react-native but due to app size I unable to start with react native. As I cannot gave app size greater than 20 MB to customers. Is there any way to reduce react-native app size less than 10 MB for all CPU architecture??



Solution 1:[1]

Facebook has released Hermes last year. Hermes is an open-source JavaScript engine optimized for running React Native apps on Android. For many apps, enabling Hermes will result in improved start-up time, decreased memory usage, and smaller app size. At this time Hermes is an opt-in React Native feature, and this guide explains how to enable it.

And also, you will able to reduce the app size by changing android/app/build.gradle file.

def enableSeparateBuildPerCPUArchitecture = true

if you set this to true, it will be able to create two separate apks(ARM, x86).

def enableProguardInReleaseBuilds = true

It run Proguard to shrink the Java Bytecode in release builds

project.ext.react = [
    entryFile: "index.js",
    enableHermes: true
]

If set this to true, Javascript will be compiled to Hermes Bytecode.

Actually, my app size has been smaller from 35M to 12M, utilizing above ways.

Solution 2:[2]

There are a couple of techniques in order to reduce your APK size:

  • Generate Separate Builds:

In your app/build.gradle set

def enableSeparateBuildPerCPUArchitecture = true
  • Enabling Proguard:

edit android/app/build.gradle:

def enableProguardInReleaseBuilds = true
  • Remove x86 from abi filters.
    splits {
            abi {
                reset()
                enable true
                universalApk false
                include "armeabi-v7a", "x86"
            }
        }
  • Generate different APK's for different architecture
    def enableSeparateBuildPerCPUArchitecture = true

You can also get here tips on how to reduce the size of your packages

Solution 3:[3]

So to reduce your app size there are multiple ways but i m going to tell you the simplest way . There are multiple step that you can follow to reduce your app size and make it compatible also for all architecture.

So the steps are :

1.Open android/app/build.gradle

2.Now make def enableSeparateBuildPerCPUArchitecture = true

Two device architecture supported by android are armebi and x86. And RN builds the native libraries for both(default).

So now in build folder you got two apk after setting the last function and upload it to the Playstore And everything will be taken care by Google like distributing the app to the correct architectures.

Version number is generated for both apk using the split generator(auto-generated).

So now you are good to go your apk size is reduced because of the split.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2
Solution 3 Aditya Shende