'How to decrease React-Native android App Size

For my react native android app, size of codes I have written is only 12KB

But package generated is of size 7.9MB. How can i decrease that.

As per Documentation for react native, I have already enbabled proguard on file app_root/android/app/proguard-rules.pro but size of didn't decrease

...
android {
    ...
    buildTypes {
        release {
            ...
            minifyEnabled true
        }
    }
}
...

Is there a solution available for this?



Solution 1:[1]

React Native app APKs include JSCore binaries for x86 and ARM. If you don't need x86 you could reduce the size to 3-4 MB.

1)In your app/build.gradle set

def enableSeparateBuildPerCPUArchitecture = true

2)remove x86 from abiFilters

this helped me in reducing size from 7.8 mb to 4.5MB

Solution 2:[2]

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

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 lil bit

And,

Set def enableSeparateBuildPerCPUArchitecture = true .

And check in android/app/build/outputs/apk/ - you will receive two apk files for armebi and x86 with approx half size of original apk.

Solution 3:[3]

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

  1. Split your app by architecture, you can split your APK by a list of well-known architectures: armeabi-v7a, x86, arm64-v8a, x86_64

    if you're distributing your application, using the play store it's a good idea to do it with the Android app bundle.

  2. Enabling prodguard will result in a lower size of the APK.

  3. Optimize your image assets, and if there's a chance try using SVG assets as much a possible.

There have been a change in the size of the resulted APK in React-Native 0.62 by enabling the new JavaScript engine which reduce the size of the native libs almost 40% Hermes Engine

These stats below are from Hermes engine and also mention the APK size reduction. enter image description here

Solution 4:[4]

release {
    signingConfig signingConfigs.debug
    minifyEnabled enableProguardInReleaseBuilds
    proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    shrinkResources true
    ndk { 
        abiFilters "x86", "armeabi-v7a" //this will help you to shrink your app size in release build
    }
}

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
Solution 2 zephyr
Solution 3
Solution 4 FortyTwo