6

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?

Kuya
  • 7,280
  • 4
  • 19
  • 31
Praveen Prasad
  • 31,561
  • 18
  • 73
  • 106

4 Answers4

6

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

ashutosh kumar
  • 207
  • 3
  • 4
  • 2
    How to remove x86 from abiFilters? – Guy Jul 25 '16 at 05:48
  • I think the line `abiFilters "armeabi-v7a", "x86"` in `android.defaultConfig.ndk`in the same file should simply be changed to `abiFilters "armeabi-v7a` – oldwizard Feb 09 '17 at 09:49
3

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.

zephyr
  • 665
  • 6
  • 19
  • Nice Answer. But one question... Is there an overview which devices support x86 and which armebi. – suther Jul 10 '18 at 15:32
2

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

BlaShadow
  • 11,075
  • 7
  • 39
  • 60
0
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
    }
}
FortyTwo
  • 2,414
  • 3
  • 22
  • 33