Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 538
Praveen Prasad Avatar asked Mar 11 '16 13:03

Praveen Prasad


3 Answers

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

like image 87
ashutosh kumar Avatar answered Nov 15 '22 08:11

ashutosh kumar


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.

like image 39
zephyr Avatar answered Nov 15 '22 07:11

zephyr


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

like image 38
BlaShadow Avatar answered Nov 15 '22 08:11

BlaShadow