Spotify ruler helps to optimize Android app size


Ruler is an open-source tool developed by Spotify to analyze Android apps and help developers figure out which of their components contribute the most to app size.

The importance of optimizing app size to increase installation conversion rates cannot be underestimated, explains former Googler Sam Tolomei. In fact, a study conducted by Google for the years 2013-2017 showed that for every 6MB increase in app size, the installation conversion rate dropped by 1%. Large APK sizes have also been shown to increase the rate of failed installs, either due to the time or cost involved in downloading, or due to connection issues. The picture gets even worse when you consider that a large percentage of users don’t have access to WiFi or large free storage capacities.

Since Android apps are currently distributed as AABs, Ruler relies on the same approach used by Google to generate APKs from AABs using Google’s bundle tool to estimate an APK size for a given device configuration. Once the APK is generated, Ruler analyzes it.

We analyze this APK to see what files actually end up in the app and how much space those files are taking up, using Apkanalyzer to ensure that the numbers reported by Ruler match the numbers analyzed by Android Studio and guarantee that we measure the app size after all optimizations made through a different process.

The next step in this process is to map each of the app’s files to its parent based on an analysis of all Gradle modules and dependencies included in the project. This provides an estimate of the size contribution of each individual module and dependency. Ruler is also able to match each component to the team that owns it based on a list of component owners.

The tool is ready to be integrated into a DevOps pipeline and, like Spotify, run on every pull request to detect regressions as early as possible.

Spotify says they’ve been using Ruler internally for over six months, with an overall reduction in their app size of around 9%. It should be noted that the Spotify app is quite complex with over 1,000 Gradle modules and hundreds of third-party dependencies, so your mileage may vary.


Comments are closed.