53

I am developing a small dictionary app by using react native with expo.

As I am compiling to Apk file. The size goes up to 30mb and after having installed on a device, it goes to 80mb.

Is this normal?

Are there any ways to reduce the size of the app?

Thank you guys.

3

11 Answers 11

56

For android APK bundle using expo, you can use the following command:

expo build:android -t app-bundle

The size will be much smaller once you upload it to the play store. This is relevant for React Native SDK 32 and earlier.

6
  • 1
    This is by far the best answer - reduced my app from 47MB to 25MB a all that I had to do was to call a slightly different build command.
    – lot
    Commented Oct 25, 2019 at 12:59
  • 1
    Yes, by far the best answer! My app went from 30MB to 12MB! Thank you!!! This should be the accepted answer!
    – Caio Mar
    Commented Dec 3, 2019 at 16:48
  • 1
    so the size will be the same on the expo build download? and then reduce on uploading to play store? Commented Apr 6, 2020 at 6:38
  • 1
    25MB is also high Commented Nov 6, 2020 at 6:10
  • @rajithShetty did you get the answer ? will the size b same for expo build and then reduce on uploading to play store? Commented Nov 16, 2020 at 14:20
40

the expo is for development the app you should migrate to react-native for production

  • make a new react app "react-native init"

  • Copy the source files over from Expo project

  • Install all dependencies of the Expo project except Expo specific libraries.

  • Make necessary adjustments to app.json file

  • Download the signing key of your Android app from Expo using exp

  • fetch:android:keystore and set it up



This reduces your app dramatically you can also enable proguard and specific build for cpu architecture

buildTypes {
    release {
        debuggable false
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
 }



for more info visit https://medium.com/@aswinmohanme/how-i-reduced-the-size-of-my-react-native-app-by-86-27be72bba640

using expo component

after you done and want publish with less size or just wan't to use a native library expo give you an option called ExpoKit this also can be used with already build with native code react projects

1-run command expo eject to add ExpoKit (choose the "ExpoKit" option)
(no need to do this if you have copied files manually or using native project)
2 -start expo packager with expo start.Leave this running and continue with the following steps.
3- link library for android and ios, this command mostly do this react-native link, sometime this will not work and you should do it manually for this means visit expokit
PS: I didn't test this so if this not work inform me

8
  • 5
    It works great, reducing from 32mb to 9mb. And, even 7mb. Awesome.
    – Sras
    Commented Apr 24, 2018 at 14:55
  • 2
    It works great, reducing from 32mb to 9mb. And, even 7mb. Awesome. However, another problem is when it is installed on device, it goes up to 22mb. How can I solve this problem?
    – Sras
    Commented Apr 24, 2018 at 15:31
  • 7
    How can I use expo specific libraries in new project?
    – Vrishank
    Commented Oct 9, 2018 at 7:21
  • 5
    Please be more specific on how to do this: Install all dependencies of the Expo project except Expo specific libraries Commented Oct 22, 2018 at 7:16
  • 10
    Wrong, Expo is not for app testing only. This answer doesn't work for those with Expo dependent libraries.
    – Caio Mar
    Commented Dec 3, 2019 at 16:08
13

Make following changes in build.gradle file located at:

./android/app/build.gradle

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

Enable ProGuard :

def enableProguardInReleaseBuilds = true

Also set minifyEnabled true and shrinkResources true

buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

Also, you can have different build types for development and release builds(depends on your user base)

buildTypes {
        debug {
            ndk {
                abiFilters "armeabi-v7a", "x86"
            }
            ....
        }

        release {
            ndk {
                abiFilters "armeabi-v7a", "arm64-v8a"
            }
            ....
        }

Also don't forget to remove the unused FONT Files

8
  • we must need to define different version codes though (e.g. def versionCodes = ["armeabi-v7a":18, "x86":19, "arm64-v8a": 20]). I failed multiple times to upload multiple apks due to this mistake.
    – Amit Bravo
    Commented Apr 29, 2019 at 13:13
  • Why should we remove x86 form abi filters? is it not needed? Commented Jun 21, 2019 at 7:59
  • @VinilPrabhu did you get any reply?
    – Yossi
    Commented Jul 7, 2019 at 17:22
  • 2
    @Yossi i didn't find any answer to this, i have kept api filters as "armeabi-v7a", "x86" Commented Jul 8, 2019 at 4:34
  • 1
    @Yossi If you don't want to support the Intel architectures or emulators then you can remove it. Commented Jul 12, 2019 at 21:00
8

As of 2021, there is now a much easier option to reduce Android binary size, since ejecting/migrating to pure react-native, switching to bare workflow and building your own binaries locally requires a lot of work and study if you don't know how to do it already or don't have your environment and tools all set up.

In app.json, make the following changes:

"expo": {
...
  "android": {
    "enableDangerousExperimentalLeanBuilds": true
  }
}

This alone should reduce app size in ~40-50% depending on your project.

There's a few things you should know about using this option, so you should read https://github.com/expo/fyi/blob/master/managed-app-size.md. It's still WAY easier than ejecting.

on top of that, you should still use app bundles (.aab) to get another ~50% size reduction after uploading to the play store:

expo build:android -t app-bundle

4
  • 3
    i have you this "enableDangerousExperimentalLeanBuilds": true my app was 80mb and now it is 59mb
    – Dafy
    Commented Feb 8, 2021 at 18:00
  • 1
    @SyedSadaifRizvi what version of expo SDK are you using? I tried the enableDangerousExperimentalLeanBuilds set to true in SDK40 but the build fails
    – Nate
    Commented Mar 8, 2021 at 23:05
  • 1
    This actually broke my app. After adding this it only works in expo but crashes after adding to play store. Commented Jun 15, 2021 at 12:02
  • 1
    @AdarshKhatri I guess that's why they put "dangerous" in the property name, probably it's a little unpredictable. I also believe it now is deprecated in favor of EAS builds, that allow a huge size reduction according to the documentation (haven't tried this yet) Commented Jun 16, 2021 at 0:16
3

You can avoid copying the source code from the existing expo project to another project as suggested in this comment

If you use eas build (not expo build) you can try to set up enableProguardInReleaseBuilds param in app.json.

Example:

{
  "expo": {
    "plugins": [
      [
        "expo-build-properties",
        {
          "android": {
            "enableProguardInReleaseBuilds": true,
          }
        }
      ]
    ]
  }
}

Reference: https://docs.expo.dev/versions/latest/sdk/build-properties/#pluginconfigtypeandroid

1
  • 1
    You have to install expo-build-properties for that : npx expo install expo-build-properties
    – Moustapha
    Commented Mar 14 at 16:17
2

the other way to reduce your app size without manually copy-paste your code in another repo. In app.json or app.config.js just set it enableDangerousExperimentalLeanBuilds to true, by doing this expo won't install the unnecessary node modules when you are running expo build:android -t app-bundle.

If you run into any crashes compare the native node modules which are installed before enabling enableDangerousExperimentalLeanBuilds and install only the required one. You can find the native node modules installed in the expo.io build artefacts.

here are some node module that come along with managed flow which you may not require

expo-ads-admob:8.3.0 expo-analytics-amplitude:8.3.1 expo-ads-facebook:8.4.0 expo-analytics-segment:9.0.0 unimodules-constants-interface:5.3.0 expo-app-auth:9.2.0 expo-apple-authentication:2.2.1 unimodules-app-loader:1.3.0 unimodules-font-interface:5.3.0 unimodules-image-loader-interface:5.3.0 unimodules-permissions-interface:5.3.0 expo-application:2.3.0 expo-av:8.6.0 expo-background-fetch:8.5.0 expo-task-manager:8.5.0 unimodules-task-manager-interface:5.3.0 expo-barcode-scanner:9.0.0 unimodules-barcode-scanner-interface:5.3.0 expo-battery:3.0.0 expo-blur:8.2.0 expo-brightness:8.3.0 expo-calendar:8.5.0 expo-camera:9.0.0 unimodules-camera-interface:5.3.0 unimodules-face-detector-interface:5.3.0 unimodules-file-system-interface:5.3.0 expo-cellular:2.3.0 expo-constants:9.2.0 expo-contacts:8.5.0 expo-crypto:8.3.0 expo-device:2.3.0 expo-document-picker:8.4.0 expo-error-recovery:1.3.0 expo-face-detector:8.3.0 expo-facebook:9.0.0 expo-file-system:9.2.0 expo-firebase-analytics:2.5.0 expo-firebase-core:1.2.0 expo-font:8.3.0 expo-gl:9.1.1 expo-gl-cpp:9.1.2 expo-gl-cpp-legacy:8.4.0 expo-google-sign-in:8.3.0 expo-haptics:8.3.0 expo-image-loader:1.2.0 expo-image-manipulator:8.3.0 expo-image-picker:9.1.1 expo-permissions:9.3.0 expo-in-app-purchases:9.0.0 expo-intent-launcher:8.3.0 expo-keep-awake:8.3.0 expo-linear-gradient:8.3.0 expo-local-authentication:9.3.0 expo-localization:9.0.0 expo-location:9.0.0 expo-mail-composer:8.4.0 expo-media-library:9.2.1 expo-module-template:8.4.0 expo-network:2.3.0 expo-notifications:0.7.2 expo-payments-stripe:8.3.0 expo-print:9.1.0 expo-screen-capture:1.1.1 expo-screen-orientation:2.0.0 expo-secure-store:9.2.0 expo-sensors:9.1.0 unimodules-sensors-interface:5.3.0 expo-sharing:8.4.1 expo-sms:8.3.1 expo-speech:8.4.0 expo-splash-screen:0.6.2 expo-sqlite:8.4.0 expo-store-review:2.2.0 expo-updates:0.3.3 expo-video-thumbnails:4.3.0 expo-web-browser:8.5.0

2
  • Has anyone tested this?
    – Muteshi
    Commented Mar 1, 2021 at 6:58
  • yes i have tested and it reduce 15mb in my case . when i run expo:build android
    – Dafy
    Commented Mar 10, 2021 at 7:30
2

My suggestion will be for you to upgrade to EAS, with EAS your build size is reduced by more than 3/4, however, at this point, you have to pay $29 but I promise you it's worth it. An app I have been working on prompting into EAS reduced the bundle size from 80MB to 16MB😱. EAS also has EAS submit which enables you submit your app to the stores in a Flash

1
1

Upgrade react-native to newer version, for different versions it is giving different size apk.

for 0.57 it was ≈12mb

for 0.59.3 it was ≈30mb

and for 0.59.9 it was ≈15mb

always try to use updated react-native version

0

There are basically two options for reducing size of apk file from 32mb(expo) to 7mb(react-native cli).

  1. Detach from expo
  2. create new react-native cli project and copy all source from expo to new react-native project.
0

Upgrade expo version to 31.exporecently launched single-SDK builds for Android. These builds contain only the SDK version the app uses when built and are both faster and slimmer. it helps for smaller standalone app build size. release note

0

Vote over here so that expo can look into the feature https://expo.canny.io/feature-requests/p/reducing-app-size Problem is react-native uses hermes so the packaging is similar to what native android app from android studio can do but since herme is like latest about 1-2year expo team has not made the support for hermes please vote.. And I also totally agree with @jakobinn

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.