Home > database >  How to reduce size of a React Native Application
How to reduce size of a React Native Application

Time:01-27

I have created a simple React native application but when I am creating the android build the size of the application is very large, around 35mb. How can I reduce my application's size? I am using :

expo build:android

CodePudding user response:

There are two ways to do this : The first one is to migrate the project to Bare React Native and then use build command or use eas feature provided by expo. Use eas build --platform for building ios or android package as it optimizes the size as well. Checkout this link for more, hope this helps.

CodePudding user response:

From your project directory, run expo eject

This will download the required dependencies and build native projects under the ios and android directories.

then go to android/app/build.gradle and change

project.ext.react = [
    enableHermes: true,  // false to true , clean and rebuild if changing
]

 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false // change to true

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false // change to true
android {
splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    }

PS: ExpoKit is deprecated and will no longer be supported after SDK 38. If you need to make customizations to your Expo project, we recommend using the bare workflow instead.

  •  Tags:  
  • Related