How to Reduce React Native APK Size

How to Reduce React Native APK Size

Ways to Reduce React Native APK Size

  1. Migrating to React Native from Expo
  2. Make Changes in android/app/build.gradle

2.1 Set def enableProguardInReleaseBuilds = true

2.2 Set def enableSeparateBuildPerCPUArchitecture = true 

 

1.Migrating to React Native from Expo

     I Love everything about Expo except the size of the binaries. Each binary weighs around 25 MB regardless of your app.

    So the first thing to do is migrate the existing Expo app to React Native. This is the simplest and coolest method to reduce your APK 

   To migrate the expo app 1st step to follow is 

   open your root directory and execute the following the command

expo eject

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

2.Make Changes in android/app/build.gradle

    This is what you have been waiting for, I know.

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

   Setting the last function creates two distinct apk in the build folder. You have to upload both of these 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 apk's 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.

 

Yeah

  So that’s how you lose weight. Reducing the size of your app has many added benefits, the best being more users will be willing to download your app. And the App won't consume more space in the user device

 

要查看或添加评论,请登录

社区洞察

其他会员也浏览了