Measure the App Size Impact of Android Libraries
Time to read: 2 minutes
Users – especially those with pay-per-byte mobile plans – will avoid downloading Android applications if they are too large. As a result, managing your Android application size helps ensure that users are not deterred from trying out your application. Google provides great strategies for reducing your application size, but many applications depend on third-party libraries which may not consider their app size impact.
Here at Twilio we understand this challenge, which is why we publish the app size impact of our Voice Android SDKs with every release. Our CI pipeline contains a size measurement step, so we ensure that we do not introduce any unexpected size regressions during the development process.
Today, we are happy to announce that we have open sourced the utility we use to measure the size of our Android SDKs: apkscale.
Measure up
Apkscale is a Gradle plugin that helps measure the app size impact of Android libraries. The plugin is designed for Android library developers who would like to measure the size of their libraries directly from their projects. The snippets below provide the steps to include apkscale in your project.
Add this to buildscript section:
Apply the plugin in your Android library project:
Apkscale adds a measureSize
task to your Android library module and, when run, scans the output directory of your library and measures the size of each .aar file present. Apkscale outputs the size report to a json file located at <yourProjectBuildDir>/apkscale/build/outputs/reports/apkscale.json
. The json file contains an array of elements that provide a size report for each .aar file measured. Apkscale provides the size in a --human-readable
format as specified by apkanalyzer. Reference the example below.
Ultimately, you will want to do something meaningful with the apkscale output. The following task demonstrates how to read the apkscale output and convert it to a markdown table similar to the table found on the Voice Android SDKs changelog.
Onward!
Apkscale provides a simple approach to Android library measurement:
- Create an APK without the library
- Create an APK with the library
- Measure the size difference between the two APKs using apkanalyzer
Apkscale works for our needs, but we are eager to hear from you about what we can do to improve!
Aaron Alaniz is a Programmable Video and Voice tech lead at Twilio. He is interested in helping mobile developers build more engaging real-time communication experiences in their apps. He can be reached at aalaniz [at] twilio.com
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.