Spotify built and open-sourced Ruler, a tool to measure and analyze the size of Android apps, built with automation in mind.

It was built to tackle the challenges that arise when working with large applications with numerous contributors that are adding features. Another consideration for building the tool is that shrinking download size has been shown to improve install conversion rate, according to Spotify.

“We set out to see how we could decrease app size, and started our investigations by using existing tools like Diffuse and Android Studio. Those work great if you want to get a high-level overview of your app, but when we wanted to dig deeper, we quickly arrived at another question — how much are certain modules and dependencies contributing to the overall app size?,” Simon Shiller, an Android engineer at Spotify, wrote in a blog post. “Ruler is a Gradle plugin that solves this exact problem. It allows you to analyze your app and gives you detailed insights into the origin and size of certain files, modules, and third-party dependencies.”

Since Android apps are packaged and uploaded to the Play Store as App Bundles that then generate an optimized Android application package (APK) for every device, Ruler captures two measurements: download size and install size to ensure that the the numbers reported by Ruler stay consistent with those analyzed by Android Studio.

Ruler scans through all Gradle modules and dependencies included in the build and analyzes which files they contain. The result of this is a second list of all components and their contents.

The second list can then be used to group all files of the app by their source and can be used to determine how much each module and dependency contributes to the overall app size.

Ruler adds a simple analyzeReleaseBundle task to your project, which you can use to execute all this logic.