Gradle & Code Quality

shrinkResources: Remove Unused Assets Without Breaking Dynamic Lookups

shrinkResources removes resources that the Android optimizer determines are unused. It is most effective alongside code optimization, but resources selected dynamically need special attention because the build may not see the runtime relationship.

By Updated 2 min read

Enable it with code optimization

For a Kotlin DSL release block:

KOTLIN · REFERENCE EXAMPLE
release {
    isMinifyEnabled = true
    isShrinkResources = true
    proguardFiles(
        getDefaultProguardFile("proguard-android-optimize.txt"),
        "proguard-rules.pro"
    )
}

This fragment belongs inside the module's buildTypes. Check the current optimizer guidance, because resource-shrinking integration has evolved across AGP releases.

Distinguish resources from arbitrary assets

Android resources, raw files in assets, native libraries and DEX code have different packaging and retention rules. A resource-shrinking setting does not promise to compress every large file in an APK.

Use the app-size guide to identify the dominant category before choosing an optimization. Removing an unused locale or oversized image may matter more than changing a code rule.

Audit dynamic resource names

Code that builds resource names at runtime, remote configuration selecting a drawable, and reflection-like lookup can hide usage from static analysis. Prefer explicit resource references where practical.

Where a dynamic contract is necessary, retain only the required names using the resource-shrinker mechanisms documented for your build version. Do not keep every resource simply because one remotely selected icon disappeared.

Compare equivalent builds

Build before and after from the same source revision, dependency set and device targeting. Compare both the archive and representative installed behavior. Bundle-generated device APKs and a universal APK are not directly equivalent size measurements.

Test language changes, dark mode, density-specific images and less common screens. The homepage working does not establish that all resource configurations survived.

Keep a recovery trail

Record which resource disappeared, how it is selected and why the retention rule is necessary. This makes future cleanup possible without repeating the same regression.

APKLint's size analysis can help locate large packaged entries, and its optimization checker can support review. Neither executes every runtime resource lookup, so use those findings to focus device testing rather than declare the release safe automatically.

Sources and further reading

  1. Android Developers: Enable optimization with R8
  2. Android Developers: Add keep rules
  3. Android Developers: Reduce your app size

Reference review: 22 September 2026. Examples illustrate the workflow; check your installed versions, release artifact and account-specific Console requirements before applying them. This guide is not a claim that APKLint executed your project or verified your private account.

APKLint

Android inspection tools and practical release guides. About APKLint · Report a correction