Android Tutorial

Android Tutorial Android Toast Button Widget In Android Tutorial Imageview Widget In Android Android Date Picker Example Android Time Picker Example Android Operating System Android Activity Android Architecture Android Content Providers Android Edittext Android Emulator Android Fragments Android Gridview Android Broadcast Receivers Event Handling In Android What Is Android Studio Android Navigation Drawer Android Recyclerview Android Scrollview Android Navigation Android Operating System Android ListView Android Studio Resources Android Studio's Layout Editor Android TextView Android Styles and Themes How To Show Image On An Android Application How To Insert An Email In Android Application In Android Version 8 How To Insert The Mobile Number On An Android Application Using Edittext Difference between android developer and web AdapterViewFlipper in Android with Example Android 9.0 Pie vs. Android 10, which one is better Android Development or Web Development which one is the best to choose Android Project Folder Structure Assets folder in Android How to reduce the size of APK in Android Top 7 Android App Development Books Top Programming Languages for Android Development Android Navigation Application Components Difference between android developer and web developer Event Handling in Android How to reduce the size of APK in Android Top 7 Android App Development Books Top Programming Languages for Android Development AdapterViewFlipper in Android with Example Android 9.0 “Pie” vs. Android 10, which one is better Android Development or Web Development which one is the best to choose Android EditText Android Fragments How to Update Gradle in Android Studio Navigation Drawer ScrollView What is Android Studio? Android Architecture Android Content Providers

How to reduce the size of APK in Android

What exactly is an APK file?

The full form of APK is Android Package Kit. It is the Android operating system's application file format. We use Android Studio to generate APK files. It is the official integrated development environment (IDE) for developing Android apps.

An APK file contains the whole software program's code and assets. Developers who build apps for Android devices must compile them into the APK format before posting them to Google Play Store, the official marketplace for Android apps. APK files must be less than 100 MB in size in order to be accepted by Google Play. Google Play assists developers with this issue by keeping up with two APK expansion files for any extra material required for their program. An APK expansion file is used to hold significant assets like media files, high-fidelity graphics, or other important assets that would otherwise surpass an APK's size restriction.

APK files may also be emailed to other Android users to be installed on their devices. If Android users want to obtain APK files from different sources and install them directly, they can allow their device permission to install unknown apps. If an Android user wants to install an APK directly because they are beta testing an unreleased version of an app or are unable to download an app through Google Play owing to a device limitation, they may choose to do so.

How to reduce APK

APK size is considered one of the most significant parts when developing an app for any company or business. No consumer wants to install a huge APK that consumes his data while downloading. The size of your APK influences how quickly your program loads, how much memory it consumes, and how much memory it demands. While developing, it is vital to keep your APK size in mind. This guide will show you how to reduce the size of your APK in Android Studio.

Some approaches for lowering the size of an Android app are as follows:

1. Generate Android App Bundle to Reduce App Size

Google provides the Android App Bundle publication format. It differs from APK creation and signing to Google Play because it contains your app's code and resources. Google Play will manage your app's bundling, generating optimal APKs for each device based on device specifications. You don't have to create several APK files for different devices when you use app bundles. To produce app bundles for your app, go to Build>Build Bundle(s)/APK(s) and then click Build Bundle (s). Your application bundle will be created.

Android App Bundle

  • It is a publishing format that contains your app's created code and resources while delaying APK compilation and Google Play signing.
  • Android App Bundles have a compressed download size restriction of 150 MB. The app bundle does not work with APK expansion files.

How to create Android app bundles?

Follow these procedures to create app bundles:

  1. Download Android Studio 3.2 or higher—it's the most convenient approach to adding feature modules and creating app packages.
  2. Include a basic module, organise code and resources for configuration APKs, and optionally add feature modules to support Play Feature Delivery.
  3. Create an Android App Bundle with Android Studio. You may also deploy your application to a connected device from an app bundle by altering your run/debug configuration and selecting the option to deploy APK from the app bundle. Keep in mind that employing this option results in lengthier build times than creating and deploying merely an APK.
  4. If you don't want to use the IDE, you may generate an app bundle from the command line.
  5. Test your Android App Bundle by generating APKs that you may deploy to a device.
  6. Sign up for Google Play App Signing. Otherwise, you cannot post your software package to the Play Console.
  7. Make your app bundle available on Google Play.

2. Delete unwanted resources

The size of an APK is determined by very small parameters like the code, graphics, and assets used in your program. To minimize the size of your APK, eliminate any unneeded sources. This will assist in reducing the size of your APK to some extent. Remove unnecessary APK sources such as unused PNGs, jpegs, and a variety of other files. Smaller graphics are also better for lowering APK size. It is recommended to utilize vector drawables rather than other image formats such as JPEG, PNG, and others. Vector drawables are modest in length, and their key advantage is that they retain their quality even when the size is increased or decreased.

3. Use Proguard

Proguard is most likely one of the most useful tools for reducing APK size. It minimizes the number of source code files and can lower the size of the APK file by up to 90%.

The following are the main functions of Proguard:

  • It makes it tough to reverse engineer the application.
  • It aids in the reduction of application size by deleting unneeded classes and functions.

Gradle Scripts > build.gradle is where you'll find Proguard in the Android app.

proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’     

4. Use the Android Size Analyzer tool

There is a plugin in Android Studio called Android Size Analyzer that will assist us in determining the amount of memory occupied by various files in our APK. Along with this Size, the Analyzer tool will provide us with some suggestions for shrinking the size of our APK. To assess your APK size, go to the build > Analyze APK option and choose your APK. You will be able to check the actual file size with distribution and the downloading size. This tool may also be used to compare the sizes of your prior APK with the new one.

5. Application of Multiple APK Files

If you do not want to generate bundles for your application, you can build multiple APK files instead. We can use Multiple APK files to accommodate various device kinds and CPU architectures.

6. Application of Vector Drawables

Try to avoid using jpeg and PNG pictures since they require a lot more memory than standard vector drawables. Vector drawables are easy to scale, and their quality does not decrease as size is increased.

7. Compress JPEG and PNG files

In most situations, graphics are the primary reason for poor performance in apps and websites. As a result, it is preferred that use compressed photos to minimize their size and improve app performance. Because the size of the image affects the APK size, it is recommended to utilize compressed pictures in your app. There are many internet services where you can compress your photographs for free.

8. Eliminate debugging libraries

Most of the developers used specialized libraries to debug their APK files. These debugging libraries also use storage space within our APK files. We may utilize the debugImplementation() function within our program only use these debugging libraries only when debugging. So, this function will help us to use the debugging libraries only when we need them and will not add them to our APK file.  

9. Reduce external library usage

During the time of adding many external features and some custom views inside our app, we have to add several external libraries. In general, adding libraries makes it simple to add new functionality to our program, but it also increases the size of our app. These external libraries will install some classes which are not required and are useless. So it is advised to use the external library as least as possible according to your usage.

10. Use of Resconfigs

When developing an Android application, many default resources are already included in the project. All of the support libraries we use on our device have local folders for additional languages we don't use in our app. These directories or folders also consume some memory space within our apps. We can use resConfigs to delete non-necessary resources from our APK, which will help us reduce the app size by a certain amount. Suppose you are developing an app for a limited audience that only speaks a particular language, such as Hindi. In that case, we will preserve the Hindi language resource and delete any other languages that are not necessary.

11. Use ShrinkResources

The ShrinkResources function is shown in the build.gradle file. This technique will delete any resources that are no longer needed for the project. You must enable it by setting it to true. We found this technique in the build.gradle file under buildTypes > release > shrinkResources. Allow it to be true.

12. Use R8 to reduce the APK size

R8 functions very similarly to Proguard. R8 shrinking is the process of reducing the amount of code to decrease APK size quickly. R8 uses Proguard rules to reduce code quicker, improving the output size.

13. Using Lint

Lint truly assists in the generation of warnings and unnecessary code within the program. As a result, this can help in the removal of the same, so minimizing the size of the application.

Conclusion

As mobile storage capacity expands, consumers are installing a large number of apps to fulfill a variety of requirements. However, as app sizes get bigger, individuals continue to face storage problems. With features like Proguard, it is simple to reduce APK files and optimize libraries. Image compression and the usage of vector graphs can also help to reduce app size.