Glance TV Optimization Part 1: Shrinking APK Size by 65%

Tarun Kumar Anchala
Glance
Published in
5 min readNov 6, 2023

--

We’ve been developing the Glance TV Application, where the primary focus is on showcasing high-quality large images (2k & 4k), live news, live sports, videos e.t.c leading to increased memory usage and a larger APK size. Our aim is to enhance app performance across a wide range of devices, from low-end TVs with less than 1 GB of RAM to high-end models. After analyzing our app, we’ve identified areas that require improvement in memory usage, APK size, CPU usage, and UI performance.

In a series of upcoming blogs, I will cover the following topics step by step

  1. APK Size (Reduced by 65% from 20.6MB to 8.3MB)
  2. App Memory (Down by 70% from 515MB to 127MB)

1. APK Size

Reducing APK size is our initial focus in app optimization. This is because a larger APK size can have significant implications:

Why APK size is important?

  1. Storage Impact: Larger APKs occupy more storage space on the user’s device, potentially leading to storage-related performance problems. Users may run out of storage for other apps or files.
  2. Memory Usage: A larger APK may require more memory to load and run the app. This increased memory usage can strain devices with limited RAM, causing performance issues.

Our goal is to improve both user experience and app performance by reducing the APK size. We’ll use APK Analyzer to identify the factors contributing to the increase in APK size.

What’s APK Analyzer:

APK Analyzer is a tool provided by Google for inspecting the contents of Android application packages (APKs). APK Analyzer helps developers understand the composition of their APK files, including the resources, assets, and code that make up their Android apps.

Drag & drop the APK into the Android Studio IDE to inspect its components.

The Initial APK size was ~ 20.6MB

1. Proguard rules :

  • By enabling minifyEnabled and shrinkResources flags and adding ProGuard rules to address build errors, we successfully reduced the APK size from approximately 20.5 MB to 15.5 MB. This represents a 25% decrease in APK size.

official docuementation: https://developer.android.com/build/shrink-code

  • While we did manage to shrink the APK size by 25% with the rules we applied, it’s clear from the screenshot that 77% of the size is still taken up by resources. This suggests there’s more scope for APK size reduction.

2. Png to Webp :

Converting PNG drawables to Webp can lead to a significant reduction in APK size, often achieving a 60%-70% reduction in asset size.

Important Note:

Optimizing WebP assets through Android Studio’s conversion process is highly efficient compared to using assets directly from designers or design tools like Figma or Zeplin. The results can be interesting in terms of APK size reduction.

Select Webp images -> right click -> convert to PNG

After conversion to PNG, now convert all these images to webp.

Select PNG images -> right click -> convert to Webp

This approach significantly reduces the APK size.

3. Remove Unused Resources :

As the Project scope increases, we might have added many drawables that are not in use. Removing these unused resources helps in reducing APK size

Navigate to “Refactor” at the top of Android Studio, then select “Remove Unused Resources.” This action will display a list of resources. Verify whether each resource is being used in your project and proceed to delete resources that are confirmed as unused.

4. Add ResConfigs :

The “resConfigs” option provides control over which language or locale-specific resources are included in your app’s APK (Android Package) file. This feature is valuable for optimizing your app’s size by excluding unnecessary resources associated with specific languages or configurations.

To include only English resources and exclude resources for other locales in your app’s APK, add the following line inside the defaultConfig block of your app's build.gradle file:

If your app supports multiple languages, add language codes like below.

5. Handling In-App Assets :

Step 1: To ensure a smooth user experience, we included high-quality images within the app to avoid slow loading times from external URLs. We optimized this by shipping 10 essential images with the APK, even though the app only displays a maximum of 5 at any given time. By reducing image count and storage consumption, we improved app performance and eliminated unexpected blank screens during image loading.

Step 2: For splash screen, we initially used an 8-second video of approximately 2MB in size, which was displayed only during the first app launch. To optimize app size and user experience, we decided to trim the video down to approximately 800KB, making it more efficient for its limited use case.

6. Font Optimization:

We received designs from multiple teams for various features, each with their preferred fonts like ‘Inter’ and ‘Poppins.’ Using multiple .ttf font files increases the app’s size. To reduce the app’s footprint, we standardized on a single font style throughout the app, eliminating redundant font files.

However, if your app requires multiple font styles, consider using Downloadable Fonts. This approach allows you to avoid embedding fonts directly within the app.

Result:

With all the above steps and some minor refactoring across the app, we successfully reduced the APK size from 20.6 MB to 8.3 MB 😍 🥳, marking an impressive ~60% reduction in APK size.

Even though the APK size is 8.3 MB, users are required to download only 7.7 MB 🥳 of the APK as shown above.

Image by fabrikasimf

In the next article, we delve into memory optimization where we’ve achieved a remarkable 70% reduction in memory usage. Explore the full details in the article 65% Smaller APKs and 70% Less Memory: How I Optimized My Android App -Part II (App Memory):

Thanks for Reading….

--

--