Imagine possessing a robot and sending it someone else over courier. It would quite a task to send it over in its real form due to the fact that it has numerous intricate parts within it. The only way you can send it over is to disintegrate it completely and pack it in a box which contains a space for all the individual parts. This package that can fit all these elements into a single space is an APK file. This package has all the elements that you need to install an Android application.
Nowadays, the sizes of these APK files are getting bigger and bigger with the growing demand for more requirements and expectations. The initial version itself had a size of two megabytes for few activities. Nowadays, the sizes of these files are growing even more, due to the increasing demand for libraries and more heavy resources. Nowadays, APKs has a size of at least 10 MB, which is quite a difference from the initial 2 MB. This rising trend in the size of APK files is for several reasons as detailed here under:
- The multiplication of dpi categories ([l|m|tv|h|x|xx|xxx]dpi)
- Increased expectations of end users
- Evolution of the Android platform and the entire Android ecosystem
Why should one keep the file size as small as possible?
As the simplicity of the codes keeps increasing, it becomes easier to unzip and install. The decompression process of all the files in the package becomes much more convenient and smooth. However, if you are a geek and want all the details, here they are:
- File size should be kept under 50 MB
- Smaller APK leads to lower lead time and hence lower download time, and that improves user experience, and, most impoSrtantly, the ratings as well.
- The future-proof code base of the android platform is the epitome of simplicity and maintainability. APKs embody these very values and adapt our systems for a more convenient experience.
What is the APK file structure?
The detailed APK file structure is as detailed below:
Most of the structure is familiar to Android developers as it mostly reflects the development project: /assets, /lib, /res, AndroidManifest.xml. While on the other hand some of the files look new, like resources.arsc which includes precompiled resources like binary XML (values, XML drawable, etc.), classes.dex contains the dex compiled version of the Java code that forms the linguistic framework of the application.
Reducing APK file size
There are several ways in which we can reduce APK size, but we can do that by taking action on any of the below-mentioned components:
- native code
- Java source code
Try to bundle densities for better optimization
Android is a very versatile platform and supports a vast number of devices irrespective of their screen size and shape. Android 4.4 and later versions support various densities: ldpi, mdpi, tvdpi, hdpi, xhdpi, xxhdpi and xxxhdpi. It is not compulsory for developers to manage and export all your assets in all these densities. So, bundling of some of these densities will help you to save resources and space. That should not affect performance or user experience in most applications. As far as smaller devices are concerned, Android automatically computes missing resources by scaling up an existing resource. It is because the hdpi/xhdpi/xxhdpi rule covers 80% of users.
Try to be selective with the use of external libraries
Android Apps development mostly relies on the use of external libraries such as Google Play Services, Android Support Library, Facebook SDK, etc. All of these libraries come with resources that are not necessarily useful to your application. Try and be selective about the external libraries you refer to.
Minimize image size
Any image that needs to be uploaded should be compressed to reduce the load on the web server. Some come with the lossless image compression algorithm.
This can be one of the most effective optimization tools and can help you to reduce the APK size. We also reuse the resources by changing their orientation. This technique also reduces the turnaround time of the project.
Using Proguard tool
It is an extremely powerful tool that optimizes and reduces the compile time for your application by removing the part of the code that is not used. It also does this by renaming clauses. It can also rename the fields, classes, and interfaces to make the core more lightweight.
Hosting content in the cloud
Hosting part of the content in the cloud with one of existing cloud backend (BaaS) platforms helps in reducing the load on the server and reducing the APK file size.
The concept and the practice of designing pertain to making the best out of the constraints themselves. Try to get the best fit and keep a design with the optimum balance between application size and features, so that the user gets the best experience. After all, your application is judged as a whole, not as a sum of severed aspects.
Try it out and let us know what your experience was like.