Android App

TechLogic

 

        Most of us are using Expo to start and/or create a react native app. But, when we eject from Expo to React-Native for production release the major problem we face is App Size.


One of the options to consider is Migrating from Expo to React Native:

Following are the steps to migrate from expo to react native without ejecting it from Expo (expo eject)

  • `react-native init` i.e. create a new project with the same name

  • Copy the source files from Expo project

  • Install all dependencies of the expo project except expo specific libraries. This will reduce huge number of `node_modules` as compare to your expo project.

  • Do necessary modifications in `app.json` file.

  • If you were using git for version control then do copy your `.git` folder into the new react native  project.

  • Now, build and test your react native app.

  • TADA! 🙌


     We need to optimize following things on which App Size of react native app is majorly depends on:

  • All JS code imported in your app (included in node_modules)
  • All native code which used in your app.
  • All assets (images, videos, media, fonts, etc)
  • All variant of devices your app supported


Reducing size of React Native App Just keep in mind, when you build a release then it doesn't contain unnecessary files and assets. So to achieve this consider to refactor and optimization of code wherever necessary.

  • Verify sizes of images from asset folder. Do remove the unused images from asset folder.
  • Verify font files `.tff`, etc. Perform necessary action to unused or large sized files.

Reducing size of React Native App (Android)

In `android/app/build.gradle` file

  •   Set `def enableProguardInReleaseBuilds = true`

 
 /**
  * Run Proguard to shrink the Java bytecode in release builds.
  */
 def enableProguardInReleaseBuilds = true

 

  This will enable ProGuard and compress the Java Bytecode.

  •  Set `def enableSeparateBuildPerCPUArchitecture = true`


 /**
  * Run to enable the native code to build for both x86 and ARMv7a
  * CPU architectures to shrink the Java bytecode in release builds.
  */
 def enableSeparateBuildPerCPUArchitecture = true


  This will create two distinct APKs in the build folder. You have to upload both  APKs to Play Store and Google would take care of distributing the app to the correct architectures i.e. armebi and x86.




https://dc-techlogic.blogspot.com/2021/03/how-to-reduce-the-size-of-react-native-app.html





1 Comments

Post a Comment