- Views: 37
- Report Article
- Articles
- Computers
- Information Technology
16 Ways To Reduce The App Size During Android App Development
Posted: Sep 09, 2019
In an era where we cannot do anything without our smartphones, the mobile application seems to play a huge role in daily lives. There is a constant notion among users to download the best app featuring enhanced applications with incredible graphics support and smooth navigation. But at the end of the day, the complaints about the size of the app covering the entire phone storage.
With passing years, even mobile companies have been increasing their storage space from 16gb in the last 5 years to 256 GB at present. But then, you have to admit that app sizes have been increasing too. Android users do face a situation where they are entitled to store images, videos, music and other documents on their cloud, but due to excessive apps on their device, it tends to slow down and keeps hanging.
Abiding by Google, nearly 90% of mobile devices function on Android OS and the total number of apps available on the Play Store is nearly 2.8 million. So, if an application is more than 150 MB, there are higher chances of less installation. The Android Developer needs to consider working on the size of the app as users are focusing more on the size before downloading the same. So, you need to curate the right functions for meeting the expectation of the user along with maintaining the size of the application.
Here are some of the ways to reduce the app size during the development period
1. Eliminate Dead Code
Your APK file size is equivalent to the loading speed of the application, the memory that it uses and the power it takes up. In such a case, if there is the formulation of any coding structure which is of no use is doing no good for your application. It is rather a wise decision to eliminate the dead code to keep your application functional and energized any time, any day. Elimination will not create any breach to the functionality. Rather removing them presents with better quality and improved performance at the same timing maintaining the code size, making it a healthy app.
2. Removing Unused Sources and Class
You need to hunt down the unused code and resources to eliminate excess unnecessary assets. You can surely make use of the tools that would prove to be highly beneficial for you.
3. Try the New R8 Code Shrinker
Code shrinking functions in reducing the size of your APK file by deleting the unused code and resources. You might get the preview of the R8 code shrinking tool in Android Studio 3.3 beta 1. Google states it helps in shrinking code faster. To try the same, you can follow the below property file while you are working with Android Studio 3.3 beta 1 or higher
4. Shrinking With ProGuard
During code formulation, you can even make the exemplary use of ProGuard for eliminating unused codes, methods, and other files.
To curate the same, follow your module-level build.Gradle file:
buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } }}
Know beforehand, ProGuard might even remove code which could be important for building your application. Better test it before applying the same.
5. Resource Shrinking
After enabling code shrinking, you can easily use resource shrinking for the identification and removal of unnecessary resources.
6. Improving Code With Android Lint
A static scanning tool for the identification of resources, Lint does not completely remove these, rather you will have to check through the reports and remove the identified ones manually.
To function with the same, first, select Analyze> Inspect Codeā¦ from the Android Studio toolbar. If there is an unreferenced resource that is detected, it will be shown in Lint's Inspection Results window.
7. Converting PNGs, JPEG and BMP into WebP
In case, if your project has several drawable, one of the best ways to reduce the size of the APK is through compressing the same. If you have minSdkVersion for your project, 18 or higher, then you can easily compress the PNGs, JPEGs and BMPs of your project into WebP format.
All you have to do is to control-click the drawable, the one that you want to convert and then select Convert to WebP. Make your choice between lossy or lossless encoding. Select Skip images when the encoded output is larger than that of the original one. Click OK to convert the image.
8. Reuse of Resources
Either reuse or remove. The choice is completely up to you. If you are willing to utilize the resources, you never know, you could do the same for the implementation of other tasks. But then you will have to keep in mind that you need to make use of the same resources for other images, customization of the same when needed. Android offers facilities for the alternation of the properties of assets. Again, there are some resources that are only a rotated equivalent of another and can be eliminated.
9. Reduce Size of Native Binaries
In the app is running on native code, the best way to reduce the quantity of native and Java codebase is through Native Binaries. It could be done through 2 ways - With the use of the arm-eabi-strip tool in Android NDK. You will be able to eliminate the useless debug symbols.
And the other procedure is to avoid fetching native libraries. This could be done by setting the android:extractNativeLibs="false" to prevent PackageManage from copying.so files from APK to file system.
10. Avoiding Enumerations
A single enumeration could add from anywhere to the classes.dex file, increasing the size of the application. The get downloaded in no time. Thus, one of the best possible ways to get rid of the same is through clearing it. You can easily make use of ProGuard and @IntDef annotation that will help to convert enumeration into integers. The final result could be a reduction in the size of your application.
11. Delivering Features on Demand
You can easily reduce the size of the APK by separating features which are not necessary for the application. It could be segmented into dynamic feature APKs, where the user will be able to download on-demand, anytime and anywhere.
For creating this module, Select File> New> New Module from the Android Studio toolbar. Then Select Dynamic Feature Module, click Next. After this, you will be able to open a Base application module dropdown and choose your base module. Name your module> Next, choose to Enable on-demand checkbox. Fusing is required if you are using Android 4.4 or lesser. Finally, you could give it a public name and click Finish.
12. Android App Bundle
Android App Bundle will only make use of the code and resources that a user will need to run the application on their device. With this, you can nearly reduce 35% of the size of your mobile application. No more using incomplete solutions, save time and effort with Android App Bundle.
The App Size is reduced in 2 ways
With the use of Configuration APK.
Uploading your app with.aab format. Google play generates 2 APKs namely single Base APK and multiple configuration APL. The first keeps the code and resources where the user will be receiving this APK. Post this, Google play scans the device configuration for generation Configuration APKs. The app is downloaded, configuration gets scanned and Dynamic Delivery Model starts functioning. Only limited space is required for the app.
Using on-demand features
If you are creating a module app, there are certain features that your users do not need. You can distribute your features in the form of dynamic feature module mentioned above, to decrease the size of your APK, making it an immaculate Android app.
13. Maintaining Multiple APK Files
As mentioned earlier, you can maintain multiple APC filed through Android App Bundles where Google optimizes APKs as per the configuration of the device. On the other hand, you can segregate multiple APKs based on specified assets. Implementation of this formula will allow the users to receive the APK which complements the features and setting of the device.
14. Formulation of Downloadable Fonts
A new edition to Android, Google recognizes most of the application on Play Store have the same fonts. Though the fonts are already a part of the app bundle, there are different applications on the same device carrying duplicates of the same fonts. And some are not even optimized for mobile devices. Google has finally decided to launch Downloadable Fonts to its Support Library 26. APIs will be able to request for fonts from a provider application and let the files download the same. This will help in reducing the size of APK files as well as save phone memory and cellular data.
15. Minimize use of Resources from Libraries
External libraries find their way while Android App Development. Commons ones among the lot are Google Play Services which is mainly used for retrieving autotranslations of app text. Another is the Android Support Library for the user to experience on data devices.
These libraries are specifically designed for servers or desktops. You get to edit files and retain only specific parts that are needed for the app. With modification functionality, you will be able to make use of the mobile-friendly library for specified features.
16. Supporting Specific Screen Densities
Android as got the number of mobile devices with varied screen densities. This further includes ldpi, tvdpi, mdpi, hdpi, xhdpi, xxhdpi, and xxxhdpi. You will not need all of it for your application. Without evening having to export the rasterized assets, you can simply support the densities.
Take a simple survey to determine the percentage of users with devices having specific densities. If the outcome is insignificant, you don't need to bundle the densities. Android will itself scale the required resources that are apt for other densities.
Here we have discussed one of the ways where you will be able to reduce the size of your Android application during the building process. There might be other simpler or easier techniques to do the same, it is all about being alert and providing the best experience within the limited range.
Concetto Labs, Chicago based company established in 2014. Concetto Labs is a leading solution provider for Cross Platform / Hybrid Mobile App development.