How to reduce apk or aab file size??

I have just started react native with expo. My first app has only one App.js file and one component of counter. When I have build it, surprisingly my apk size is 49MB :open_mouth: I wonder why its so and how to reduce it without ejecting???


There are a number of reasons for the large size.

  • The APK includes native code for x86 and ARM in both 32 bit and 64 bit versions (so basically 4 times the amount of native code).
  • The way the managed workflow works is that it includes a bunch of functionality in case it is needed.
  • One of the things included in a managed workflow app is the face detector which includes some large data files.

Currently you can’t do anything about the last two points unless you eject, but the Expo team is working on making this better, e.g. If I remember correctly they’ve mentioned that they are working on ways to customise the build to exclude certain things. I believe there are some technical difficulties with this that they need to resolve before this happens.

What you can do something about is the first point. If you build an AAB file instead of an APK file then the Google Play store will send to the device only the native code relevant to the device instead of all 4 versions. So although the AAB file will also be large, the resulting app on an actual device should be quite a bit smaller.

1 Like

Thanks for the prompt response.

So, I need to keep building my without considering it at this level?? I mean its has only one file and one image, and its 49MB; what If I build the whole app with lots of files and images? It would go more than 1000MBs then - its astonishing.

1 Like

The native code, React Native/Expo JavaScript code and face detector data files are basically a fixed overhead. So it’s not like 1k App.js = 50MB, 2k JavaScript = 100MB or something like that.

So the app will start out with most of the space taken up by React Native/Expo code and data, but as you add more of your own code, dependencies and assets, the balance will shift towards your stuff taking up more of the space. If you have a lot of large images then of course the app is going to be very large, but at that point, Expo’s code/data will be a small percentage of your app’s size.

As an example, an APK I build for one of my apps is 45MB. If I unzip it, it’s 119MB.

Of that 119MB, 84.6MB is the native code (between 16MB and 24MB for each of the 4 types). That size is not going to increase as you add more stuff to your app.
The next biggest part of the app is the assets. These are 11.5MB in total, with about 9.8MB of those being to do with the face detector. 1.5MB is the JavaScript bundle made up of my code, JavaScript dependencies of my code and Expo/ReactNative JS code. The face detector data is not going to increase as you add stuff to your app. The JS bundle will, but that will mostly be your code and any JavaScript libraries you explicitly depend on.
There are more static files besides the above.

So over 90% of the unzipped APK is fixed overhead and will not grow as you add more code and assets.

1 Like

Alright … Thanks for your response.

Now that I am aware of the stuff, I am confident to proceed and finger crossed for the fixes from expo.

1 Like