Android tutorial

Reduce apk size android 2022

Reduce apk size android

how to Reduce apk size android APK size is very important for mobile devices. Personally, I love small APK sizes. The APK Size is a measure of how fast your app loads. It will affect the performance of your APP. We should take into account some factors when developing the application. Reduce apk size android.

A large APK can take up most of a user’s Network/Wifi Bandwidth and, most importantly, it could occupy most of the space on his mobile device. Reduce apk size android.

Your APK’s size can have an impact on the speed of your app loading, how much memory it uses and how much power you use. Reduce apk size android.

Mobiles are often limited in space and memory, so optimizing the app size is crucial. What are some ways to increase the size of our Android-Development apk? Let’s get started.

Reduce apk size android

Understanding Android App Bundles An Android Application Bundle publishes all of your app’s compiled source code, defers APK generation, and signs to Google Play.

Google Play uses your app bundle for optimizing APKs for each device configuration. This means that only the code and resources required for that device are downloaded in order to run your app. To optimize support for different devices you no longer need to sign and manage multiple APKs. Users get smaller and more optimized downloads.

android-app-bundle-format

Image Credit: Google Android Official Website.

Android App Bundles – File Targeting and Serving

  • What does this mean for File targeting? Let’s assume we have hdpi (xhdpi), xxhdpi and xxhdpi in our app. The device that the application is being downloaded will determine whether it has hdpi resources.
  • Multilingual applications (English, Spanish and French) will be rejected. Only the specified string resources will be downloaded to the device.
  • This allows you to save space on your device’s memory.

Android Size Analyser Reduce apk size android

Android Studio has the Android Size Analyser plugin that allows you to see which files are taking up the most space. To install the plugin

  1. Select File > Setting (or, on Mac, Android Studio > Preferences.
  2. Scroll down to the plugins section.
  3. Click on the Marketplace tab.
  4. Look for the “Android Size Analyzer” plugin.
  5. To install the analyzer plugin, click the Install link.

After installing the plugin, restart the IDE. To analyze your application, click Analyze> Analyze App Size in the menu bar. You will see something similar:

These recommendations can be used to reduce the size of your app in a more efficient way.

android-size-analyser-plugin

1. Unused Resource 

Vector drawable can be used in place of JPEGs and PNGs images. Android Vector Drawable already contains some default icons.

Google also developed WebP, another popular image format. This image format focuses on image quality, and optimization. WebP is a superior image format than JPEG and PNG. This format is high quality.

2.Lint

Lint can generate warnings and unused code within the application. This can be used to remove the warnings. Then, resolve the warnings and try to compile the code.

3. Proguard

Proguard can also be used to reduce the size of your application by removing unneeded classes and methods. This makes it difficult to reverse engineer your code.

buildTypes {
      release { 
          minifyEnabled false 
          proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
           'proguard-rules.pro' }
      }

3.Utilization of ShrinkResources

In the build, you will see the ShrinkResources method. Gradle file. This will eliminate resources that are not being used for the project.

It must be enabled by declaring that it is true. This method is available in build.Gradle file > createTypes > release > shrinkResources. Make it true.

buildTypes { 
         release { 
             shrinkResources true 
     }
 }

5. Limit the use of libraries from other countries

These external libraries will install classes, but some classes aren’t required. This can cause storage to be used and increase APK size. To reduce APK size, it is better to limit the use of external libraries.

6. Use your code again

Use the most appropriate design pattern. Repetitive codes will cause files to grow in size, which will result in an increase of APK size.

7. Reduce the size of APK with R8

R8 functions in the same way as proguard. R8 shrinking refers to the process of reducing the code. This helps reduce APK size. R8 uses proguard rules to shrink code faster and improve the output size.

Proguard is slower than R8 because there are fewer steps. Optimized, it reduces the app’s size.

R8 shrinking allows us to reduce the code in our application. This results in a reduction of the APK size. R8 does the majority of the work for Proguard. Why should we prefer it? It works with Proguard rules, shrinks code faster, and improves output size.

It’s so much better than understanding these steps and then implementing them in our applications to deliver an optimized appk to our customers.

This is it.

We hope this article helped you understand the different ways to reduce Android app size.

We are grateful for your time.

8. Reduce the library size

You can also double-check external libraries and use the official Google libraries.

9. DebugImplementation

You can delete any debug libraries you have in your app. This can be accomplished by using DebugImplementation when building a testing debug apk.

debugImplementation 'com.amitshekhar.android:debug-db:1.0.1'

 

Read More Tutorial