41

I am working on react native project , but whenever i am building an Apk file , it give me Apk of 47MB. I tried every documentation which i found useful on google but nothing works for me, Is there any way to reduce my App size below 10MB as the app only contain three or four pages. Any help would be appreciated

6
  • 2
    Can't you delete any library from your app?
    – MMG
    Commented Mar 11, 2020 at 6:07
  • 1
    if you generate google app bundle and then upload it into play store ,it will reduce your apk size .
    – nazmul
    Commented Mar 11, 2020 at 6:08
  • 1
    no because it only contains the library m using . Commented Mar 11, 2020 at 6:11
  • 1
    @nazmul but i want to decrease apk size Commented Mar 11, 2020 at 6:13
  • why don't you give it a read developer.android.com/topic/performance/reduce-apk-size
    – nazmul
    Commented Mar 11, 2020 at 6:14

7 Answers 7

36

You can try following steps

  • 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 artitectures armebi and x86. By default RN builds the native librariers for both these artitectures into the same apk.

Setting the last function creates two distinct apk in the build folder. You have to upload both of this 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 apks in the order of 104856 and such. This is auto-generated by the build to avoid version conflicts, so don’t freak out (I did). This split reduced the apk size from around 7MB to 3.5MB for arm and 5MB for x86 respectively.

You can find more information in this article https://medium.com/@aswinmohanme/how-i-reduced-the-size-of-my-react-native-app-by-86-27be72bba640

3
27

Seem like android app bundle can help you. But i will also answer the question how to reduce Android APK size in react-native

there are many ways to optimize app install size of a mobile app build with react-native.

a react-native app size depend on:

  • total Js code imported in your app (included in node_modules)

  • total Native code use in your app.

  • Total assets (images/ videos/ media ...)

  • variant of devices your app supported

To reduce / optimize your app size, you have to optimize 4 things above

First, js code

We write JS code, react components then update, replace by new others. By times, js code base growth. and become mess & smelling, useless but hard to remove from code base. It make your app size growth by still imported in your code base but never to be use.

-> Check, refactors your JS code after 1 / 2 phase of features development to make your code beauty & lean.

Second, Native code

  • Native side seem like a mystery cave with JS react-native developers and beginners. In native libraries have a ton of Java / Objective-C codes which hard to reach by developer. Some of their un-controlled or not necessary.

Abuse native libraries can soaring your app size and make some weird crashes

-> Don't use native libraries if you don't need it or you can do it by js code. -> use Proguard to thin your app size by shrink code and remove unused codes. My apps reduced 15% - 20% app size after configured proguard.

Learn more about proguard here

Third, Assets

Assets like images, sounds or video are usually have high weight. To optimize assets you can use some tips below:

  • use webp format images

  • do not abuse png, gif format if jpg is enough

  • Optimize image files size using some tools like tinypng.com It's pretty good and fast

  • use vector icons. Like react-native-vector-icons

  • Do not included high weight assets in bundle, you can processing download and setup they when first times users open app.

Last, config variant of devices your app supported

  • If your app target some specify devices, os versions. You can limit it, remove unsupported architectures. It's can reduced 2% -> 10% base on what you removed.

  • Use Android app bundle, it's recommended by Google. if your app sold in Play Store. It will separate your bundle file into many installable apk files base on device types. So your app only included assets / code necessary for only this device type. Amazing, right?

    Learn more about Android App Bundle here


one of my apps if build for type APK is 40MB. When build type AAB is 40 MB. But install file from Goole play store only 13 -> 17 MB depend on device types.

9

Switch on these options

def enableProguardInReleaseBuilds = true
def enableSeparateBuildPerCPUArchitecture = true

Find alternatives for large-sized modules

Use cost-of-modules (npm package that will list the size of packages in your peoject) ... and try to find an alternative for costy-packages

0

Build .apk to .aab file and then deploy .aab file to google play console. please read about app bundle concept in devloper site. https://developer.android.com/guide/app-bundle

1
  • Thanks for your response. Its an internal app, we don't have to upload same on google play console. We have 4 to 5 simple pages with crud operations and size is 47 mb of app Commented Mar 13, 2020 at 7:19
0

You cannot do much about it . by using def enableProguardInReleaseBuilds = true can compress the app a bit . Use .aab bundle instead of apk format and uplaod it to Play store google play will compress the app further .If you are using play store and bundling your app in .aab format you need to do separate apk by enablingdef enableSeparateBuildPerCPUArchitecture = true For more Info https://developer.android.com/studio/build/configure-apk-splits

1
  • should we enable enableSeparateBuildPerCPUArchitecture before making bundle? Commented Sep 21, 2021 at 6:47
0

Open up android/app/build.gradle and edit the following code as shown.

***lATEST method ***

def enableSeparateBuildPerCPUArchitecture = true

def enableProguardInReleaseBuilds = (findProperty('android.enableProguardInReleaseBuilds') ?: true).toBoolean()
1
  • 1
    What do you mean by "latest method"?
    – Kibartas
    Commented Jul 4, 2022 at 13:58
0
  1. Remove unwanted Codes and unused Packages.
  2. inside the app/build.gradle

Set values into true

def enableProguardInReleaseBuilds = true
def enableSeparateBuildPerCPUArchitecture = true

And

buildTypes {
    release {
        debuggable false
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}
  1. use this command to build

    gradlew bundleRelease

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.