Why app size still matters

Download size directly affects who can install an Android app. Users on slow networks or devices with limited storage will skip an oversized APK, and install conversion rates are known to improve as download size shrinks. That makes keeping the app lean a concrete product goal, not just a hygiene issue.

The challenge is figuring out what is actually making an app large. For a codebase with more than 1,000 Gradle modules and hundreds of third-party dependencies, all merged and packaged into one APK, attribution is nearly impossible with standard tooling. Existing options like Diffuse and Android Studio give a high-level picture but don't answer a basic question: how much does each module or dependency contribute to the final size?

Spotify built Ruler, an open-source Gradle plugin, to answer that question and to make the measurement repeatable and automatable.

How Ruler measures an app

Ruler works from the artifact most Android apps are shipped as: an App Bundle. It uses Google's Bundletool to generate an APK for a specified device configuration, so the measurement reflects what actually lands on a user's device rather than what sits in a universal APK. It then analyzes that APK with apkanalyzer, keeping the numbers consistent with what Android Studio reports and ensuring measurements capture the effect of post-processing steps like R8.

For every file in the APK, Ruler records two numbers:

  • Download size: bytes transferred over the network during download
  • Install size: bytes occupied on device after installation

Tracing files back to their source

After the APK analysis, Ruler has a list of files and their sizes. To attribute those files, it scans every Gradle module and dependency participating in the build and records which files each one contains. The two lists are then cross-referenced: every file in the APK is grouped by its originating component, giving a per-module and per-dependency size breakdown.

Execution is a single task, analyzeReleaseBundle, which produces two artifacts: a JSON report for programmatic consumption and an HTML report for manual exploration.

Measuring classes inside DEX files

Android compresses all classes into one or more DEX files. Because information is shared between class entries within a DEX file, a single class's exact contribution cannot be isolated perfectly. Ruler approximates it by taking the raw class size and scaling it proportionally to the total DEX file size.

Attributing size to owners

Knowing which module is large is useful; knowing which team is responsible for it is more so. Ruler accepts an optional mapping of component owners. When provided, it aggregates size contributions by owner, which helps route questions and follow-ups to the right people.

Figures above are for illustrative purposes only.

Ruler in Spotify's workflow

Spotify has used Ruler in production for over half a year. Daily exports from the latest main build feed a historical trend dataset covering the whole app and individual components. In addition, Ruler analyzes the size impact of every pull request, giving developers feedback before a regression can be merged. The effort has so far reduced the app's size by roughly 9%.

Running and extending Ruler

Ruler is available on GitHub, where the setup guide is kept current. Applying the plugin and running the one Gradle task is enough to get reports for a project.

The tool is written in Kotlin and uses Kotlin Multiplatform. It is actively developed, and Spotify considers it part of its contribution back to the open-source ecosystem. Issues and pull requests are both welcome, with the stated goal of making Android apps accessible to a wider audience.