Based on a Statista report, it has been found that mobile app revenue is likely to increase in the coming years. It will go up by approximately 613 bn USD by 2025. Eventually, the demand for react native app developers will also increase making react native app development the most preferred approach. As the framework is cross-platform driven, it is preferred the most.
While developing react native app, you can either select Expo CLI/ the managed workflow or React Native CLI/ the bare app development workflow. If you are eager to know about the difference between React Native CLI and Expo CLI, you should check the article.
As is already covered in the other article, we will focus on reducing the react native app size at the Expo.
Concern about APK size
Building a react native app with Expo toll is quite easy but the main issue lies in its size. For a simple “Hello World” expo app, the apk size is more than 30 MB. In case users have a lack of space on their device, they have to compromise other apps to install the Expo built apk. On this note, the solution to reduce its size is urgent.
If you are in the same struggle, you are at the right place.
Before proceeding with the actual steps of reducing the apk size, let’s dig deep into the reason behind this concern.
Why is the Expo app size so big? The huge size of such Expo applications is because several built-in APIs get installed with the app. Also, the architectural layout contributes to its increase in size. The Expo SDK is built into the app, which unnecessarily makes it bigger. The Expo tool increases every bit of its binary size.
Here, we have covered 4 different approaches to reduce the size of apk.
4 Key methods to reduce the size of the apk file
1. Relying on EAS build or Classic build
EAS (Expo Application Services) Build is the hosted service using which you can build Expo projects and React Native app binaries. With the EAS build, you can also export the codebase used for the app development. You should consider this EAS bud for making apk size small. As it runs the prebuild in JS frameworks, it can be effective. You can also use the EAS build to easily compile the project.
Let’s understand the process by which EAS building works.
EAS build connects all the dependencies that are installed during native project development. You can find all these dependencies in the create package.json file.
Using this approach, you can develop an app of a minimum of 3 MB size. Based on the Expo SDK or react native version, the apk size can differ.
2. Considering Play store data
This approach tells that at the initial stage, users or developers should not consider the huge size of the build. This will be taken care of afterward as the Apple app store or Google play store disintegrates the build-up into small binaries. Also, it is suggested to build the Android App Bundle or .aab version of applications. It is much better to deal with the .aab file format rather than the .apk file due to the latter’s large size. Also, it is advised to upload applications in the AAB format. This way you get the scope to deal with much smaller apps.
What matters is the ultimate size of the download for distinct devices. Do you have to start the process by distributing binaries to different app stores.?
What is the difference between the .aab file and .apk file?
.apk and .abb file formats are different in their flexibility and the pattern of their architecture.
|A publishing format is installed on the actual device.||A Packaging format.|
|In the AAB file format, you only use the codebase that is required to run applications.||In the APK file format, you have to use heavy code lines that may be irrelevant to the system configuration.|
|Dynamic delivery is supported.||Dynamic delivery is not supported.|
Using the bundle file format of Android, you can both distribute and create apps on the basis of the user’s device configuration. Thus you can optimize the size of the app.
4. Migrating Expo-built applications to React Native
This can be an effective method to reduce the apk size.
- Build a new react native CLI project using the command react-native init in the cmd.
- Copy source files from the Expo project.
- To get rid of the heavy binaries, don’t install the Expo libraries. You should install the dependencies that you may require.
- Some modifications in the app.json file are needed. These changes are in UI designs, app version, and logo.
- Open the .git folder in your created react native project.
- Now you have to download the “signing key” of the developed app. It is also the Encryption key with which you can publish applications in the Google Play store. For this, you have to use the exp fetch:android:keystore.
- After you are done with the app setup and testing, you will be able to get a much smaller application of 7 MB.
5. Change in the VS Code
This fourth and last step is the most effective method for reducing the apk build size.
- Open the android/app in your project code editor and then go to build.gradle.
- Find ‘enablepro’ and make the def enableProguardInReleaseBuilds = false to “true”. This enables the Proguard to reduce the size of Java Bytecode.
- You have to repeat it for def enableSeparateBuildPerCPUArchitecture = false as well. This step modifies certain operations in Proguard. Refer to the below-attached image.
- Changing both the def enableSeparateBuildPerCPUArchitecture and def enableProguardInReleaseBuilds to “true” will enable the build configurations. This will eventually allow you to create individual .apks for all the available architectures.
- You will also be able to reduce the Java Bytecode by making the enableProguardInReleaseBuilds to “true”.
- As the last step, include a command enableProguardInReleaseBuildsshrinkResources true after the option minifyEnabled.
- Go ahead building apps and distinct .apks in the output directory. You can also find armebi and x86 for separate architectures.
You have removed all the irrelevant resources and codebase. Hence, the apk build size is reduced to a titbit amount.
Reducing the apk file size built with the Expo tool can be difficult but not impossible. This article gives you the 4 different approaches with which you can surely deal with the issue. Also, if needed in the future, rely on the Turtle CLI version rather than the Expo CLI. With Turtle CLI, you can create Expo standalone apps. Most importantly, the app-building process does not depend on the app builder’s stability.