When installing apps on the Google Play Store, users typically prefer smaller app sizes. That may be because of limited storage space or limited download bandwidth, or some users even just prefer a quicker install. Nevertheless, Spotify has a tool called "Ruler" that it uses to measure and analyze the size of its Android apps for the purposes of figuring out how to shrink them down. Now the company is making that tool open-source and free to use for any developer that wants to use it.

Apps published on the Google Play Store are now typically uploaded in the form of an Android App Bundle. When a user requests an app for installation, the Google Play Store then generates an optimized APK for the end-user that is installing the app. Ruler mimics this process to create an APK accurate to what the end-user should receive. For each file, Ruler then captures two measurements:

  1. Download size:Â Bytes transferred over the network when a user downloads the app
  2. Install size:Â Bytes a file takes up on the device once the app has been installed

Ruler can then scan through an app and find the list of files inside of and their sizes. It can also find all of the Gradle modules and dependencies that contribute to the size of the app. Through this, a second list is created of all components and their contents. Combining both lists makes it possible to group all files of the app by their source and determine how much each module and dependency contributes to the overall app size. There are other methods involved too, and it's worth checking out the company's engineering blog post to learn more.

Spotify says that the main Spotify app has over 1,000 Gradle modules and hundreds of third-party dependencies, and that Ruler has helped to reduce app size by just over 9% in the past six months. The company says that it exports app size data once a day, using the latest main build. It can use this data to track historical trends, both of the app as a whole and of individual modules and third-party dependencies. The app size impact of every pull request is also analyzed so that early feedback can be given to developers.

Ruler is fully written in Kotlin, and to use it, all you need to do is apply the plugin to your Android project and run a single Gradle task. You can check out Ruler's GitHub to learn how to integrate it into your project.