Mobile Development 15 min read

How to Shrink Your Android APK Size: Practical Tips and Tools

This guide explains how Android developers can understand APK structure and apply a range of techniques—such as removing unused resources, compressing images, using vector drawables, and optimizing native code—to significantly reduce the size of their application packages and improve download and install performance.

Tencent TDS Service
Tencent TDS Service
Tencent TDS Service
How to Shrink Your Android APK Size: Practical Tips and Tools

Users often avoid downloading large apps, especially on unstable 2G/3G networks or when data is metered. This article describes how to reduce APK size so more users are willing to install your app.

Understanding APK Structure

An APK is a ZIP archive that contains all files of your app, including Java class files, resources, and compiled resources. META-INF/: contains CERT.SF, CERT.RSA signature files and MANIFEST.MF for verifying the APK. assets/: holds app assets accessible via AssetManager. res/: contains resources not compiled into resources.arsc. lib/: stores compiled native code for each CPU architecture (e.g., armeabi, armeabi-v7a, arm64-v8a, x86, x86_64, mips).

An APK also includes the following files, of which only AndroidManifest.xml is mandatory: resources.arsc: compiled resources, containing XML from res/values (strings, styles, layout references, etc.). classes.dex: Dalvik/ART bytecode. AndroidManifest.xml: main manifest with app name, version, permissions, minSdkVersion, targetSdkVersion, etc., stored in binary XML.

Reduce Resource Count and Size

APK size affects load speed, memory usage, and battery consumption. The simplest way to shrink an APK is to reduce the number and size of resources.

Remove Unused Resources

Android Studio’s lint tool detects resources in res/ that are not referenced by code and reports warnings such as:

res/layout/preferences.xml: Warning: The resource R.layout.preferences appears to be unused [UnusedResources]

Note that lint does not scan the assets/ directory, which may contain resources referenced via reflection or libraries. Lint only warns; it does not delete resources.

If your dependencies contain unused resources, enable shrinkResources in build.gradle. This works together with code shrinking (ProGuard/R8) to remove both unused code and resources.

Minimize Third‑Party Library Resources

When using third‑party libraries, you may import unnecessary objects and methods. If the library’s license permits, edit the library to keep only needed parts, or replace it with a lighter alternative.

Code shrinking can strip unused library code, but it cannot remove large internal dependencies.

Support Only Selected Screen Densities

Android supports many screen densities (ldpi, mdpi, tvdpi, hdpi, xhdpi, xxhdpi, xxxhdpi). You can omit resources for densities rarely used; the system will scale existing resources.

For purely scalable images, place them in drawable-nodpi. It is recommended to keep at least xxhdpi assets.

Reduce Animation Frame Count

Frame animations increase APK size because each frame is a separate PNG. Halving the frame rate (e.g., from 30 FPS to 15 FPS) cuts the number of images in half.

Use Drawable Objects

Instead of static image files, use XML drawable objects, which occupy minimal space and can follow Material Design guidelines.

Reuse Resources

Rather than storing multiple variants of the same image (colored, shadowed, rotated), reuse a single image at runtime and apply tint or transformation programmatically.

For Android 5.0+, use android:tint and android:tintMode; for older versions, use ColorFilter.

Example of rotating an arrow 180°:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/ic_arrow_expand"
    android:fromDegrees="180"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="180" />

Draw Images Programmatically

Drawing images via code eliminates the need for stored image files, further reducing APK size.

Compress PNG Files

The AAPT tool can losslessly compress PNGs in res/drawable/. It can convert PNGs with fewer than 256 colors to 8‑bit PNGs, saving memory.

Limitations:

AAPT does not compress PNGs in the assets/ directory.

Compressed PNGs may use fewer than 256 colors.

AAPT may increase size of already‑compressed PNGs; set cruncherEnabled = false in Gradle to disable.

aaptOptions {
    cruncherEnabled = false
}

Compress PNG and JPEG Files

Tools like pngcrush, pngquant, zopflipng reduce PNG size without quality loss. pngcrush iterates over filters and zlib parameters to find the smallest output.

For JPEGs, use packJPG. Google’s guetzli encoder can produce JPEGs 20‑30 % smaller at comparable quality.

Use WebP Format

WebP offers lossy compression with transparency and higher compression ratios than PNG or JPEG. Drawbacks: not supported below Android 3.2 and slower decoding.

Google Play requires the app launch icon to be PNG.

Use Vector Drawables

Vector drawables provide resolution‑independent icons; a 100 B XML file can generate a clear image at any size. However, rendering large vectors can be slower, so limit their use to small images.

Reduce Native and Java Code

Various techniques can shrink Java and native code size.

Eliminate Unnecessary Generated Code

Understand and prune automatically generated code (e.g., protocol buffers) that can double app size.

Replace Enums

Each enum adds 1–1.4 KB to classes.dex. Use @IntDef with ProGuard instead of enums for similar type safety.

Reduce Native Library Size

When using the NDK, strip debug symbols with arm-eabi-strip for release builds.

Avoid Extracting Native Libraries

Set android:extractNativeLibs="false" in the manifest to keep native .so files compressed inside the APK, reducing update package size.

Maintain Multiple Small APKs

Split your app into multiple APKs based on factors such as screen size or GPU texture support. Devices download only the APK variant that matches their configuration, avoiding unnecessary resources.

mobile developmentAndroidresource managementAPKsize optimization
Tencent TDS Service
Written by

Tencent TDS Service

TDS Service offers client and web front‑end developers and operators an intelligent low‑code platform, cross‑platform development framework, universal release platform, runtime container engine, monitoring and analysis platform, and a security‑privacy compliance suite.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.