Cutting the Fat: Our Journey to Shrink PW Android App by 70%
by Vikas Gupta
When the size of an Android app becomes too large, it can negatively impact user experience — leading to slower downloads, longer installation times, and even higher app abandonment rates. Our Android app originally clocked in at 150 MB, and after careful optimization, we successfully reduced its size to 40 MB, a reduction of 70%. Here’s a breakdown of how we achieved this drastic reduction.
1. Understanding App Size Metrics
Before diving into optimizations, it’s critical to understand the key metrics that affect app size:
- Download Size: The size of the APK or AAB file users download from the Play Store.
- Install Size: The space required on the user’s device once the app is fully installed. This is typically larger than the download size.
- Compressed vs. Uncompressed Size: Files such as images, fonts, and resources often get compressed during the download, but take up more space once decompressed during installation.
- Native Libraries: The size contribution of native libraries like
.so
files, which can vary based on the number of supported architectures (e.g., ARM, x86).
These metrics help us pinpoint the biggest size contributors and identify areas for optimization.
2. Why App Size Optimization is Important
App size optimization isn’t just about making an app smaller; it’s about improving the overall user experience. Smaller apps mean faster downloads, less storage usage, and higher user retention, particularly in markets where mobile data and storage are limited.
Google conducted an experiment providing users with identical builds of apps, artificially inflated in size. The experiment revealed that for every 6MB increase to an app’s size, the app’s installation-conversion rate decreased by 1%. The implications are profound, leading to a multitude of missed opportunities. Optimizing app size directly impacts download success rates, especially on low-end devices, and ensures better accessibility.
3. Profiling Tools: Tracking and Analyzing App Size
Several profiling tools were key in analyzing and reducing the app size:
- Emerge: A tool for visualizing and tracking APK size. It breaks down the size contributions from classes, resources, and assets over time, allowing for continuous monitoring link.
- APK Analyzer: Available in Android Studio, this tool provides a detailed size breakdown of APK contents, from libraries to resources. It helps identify the largest contributors to app size and assists in investigating potential areas of improvement.
- Bundle Tool: Essential for analyzing Android App Bundles (AAB), this tool helps visualize the size distribution across different modules and provides insight into how features can be delivered dynamically.
- Ruler: An open-source tool that generates detailed reports on APK size and provides insights into potential size regressions, enabling teams to track optimizations effectively link.
4. The Steps Taken to Reduce App Size
Over the course of several months, we implemented a series of targeted optimizations to shrink our app:
- Zoom SDK Separation (Reduced ~60 MB): The Zoom SDK contributed a significant 60 MB to the app size, but it was only used by a small percentage of users. Dynamic Delivery was explored but not supported for this SDK, so a separate app was created specifically for students who required the Zoom functionality. This decision allowed us to shed a large chunk of the size by offloading the SDK.
- Code Removal of Legacy Features (Reduced ~3 MB): Many outdated features and flows were retained within activities and fragments, though they were no longer actively used. By removing these obsolete features, we reduced the app size by about 3 MB.
- Removing Redundant Libraries (Reduced ~10 MB): Several libraries serving similar functions were identified. By consolidating and removing redundant libraries, the app’s dependency footprint was reduced by approximately 10 MB.
- Downloadable Fonts (Reduced ~2 MB): Rather than bundling custom fonts in the app’s resources, Downloadable Fonts were implemented. This allowed fonts to be fetched dynamically, reducing the size by 2 MB without sacrificing typography flexibility.
- Converting PNG/JPEG to WebP (Reduced ~5 MB): Image assets were optimized by converting PNG and JPEG files into WebP, a highly compressed and efficient image format. This reduced the overall size of the image assets by 5 MB without compromising quality.
- Dynamic Delivery for Feature Modules (Reduced ~4 MB): Some feature modules were converted to Dynamic Delivery, meaning they are downloaded only when needed by the user. This modular approach reduced the size of the base APK by 4 MB, as not all users required access to all features at once.
- ProGuard Rule Optimization (Reduced ~13 MB): A review of the ProGuard rules revealed that one library had introduced generic rules that caused unused classes to be retained. After refining these rules, the final APK size was reduced by an additional 13 MB.
5. Monitoring and Maintaining the Size Reduction
To ensure that app size optimization is maintained, a series of monitoring practices were implemented:
- Python Script for Image Size Check: A Python script was added to the pipeline to check the size of any new images in each merge request (MR), ensuring they do not exceed 20 KB. This ensures image assets remain optimized.
- App Size Reports for New Features: Each new feature must be accompanied by an app size report, with a limit of 100 KB per feature. This ensures new features are designed with size in mind.
App Size Reports on Release: With the help of Ruler, app size reports are generated and shared with every release. These reports provide visibility into the size contributions of each feature and help detect size regressions early on.
6. Future Scope for Size Reduction
While the app size was reduced by 70%, there are still additional areas for future optimization:
- Enabling R8 Full Mode: R8 is an optimization and shrinking tool that can be run in full mode to provide deeper optimization at the code level. This will likely result in further size reductions.
- Dynamic Delivery for Assets: Beyond feature modules, Dynamic Delivery can be extended to deliver large assets (such as videos or large datasets) only when necessary, further reducing the base APK size.
By implementing these strategies and tools, the app size was successfully reduced from 150 MB to 40 MB, a reduction of nearly 70%. This optimization not only improves the app’s accessibility and performance but also enhances the overall user experience, particularly in regions with limited data or storage resources.