Google Brings Optimized Resource Shrinking in Latest Android Gradle Plugin
Briefly

Google Brings Optimized Resource Shrinking in Latest Android Gradle Plugin
"The latest version of the Android Gradle Plugin (AGP) introduces an optimized resource-shrinking approach that unifies code optimization and resource shrinking, achieving up to 50% reduction in app size for apps that share significant resources and code across different form factor, says Google. In the new approach, Android's long-standing optimizer R8, processes code and resource references at the same time, which makes it possible to identify all resources that are only referenced from unused code, and thus remove them along with the unused code."
"This completely eliminates the need for the unconditional keep rules generated by AAPT2 (the resource packaging tool for Android) and provides much more fine-grained and precise information for discarding unused code and resources. In previous versions, AAPT2 generated unconditional keep rules before R8 optimized the code, often causing them to reference unused code and preventing R8 from removing that code along with its associated resources."
"As mentioned, the new R8 optimization pipeline can achieve over 50% improvements in apps that share significant code and resources across different form factors, while also providing measurable benefits for smaller apps. With the new optimized behavior, developers now have four distinct approaches to app optimization: no optimization, R8-only, R8 with resource shrinking, and optimized resource shrinking. Each successive step provides additional benefits."
AGP 8.12.0 adds an opt-in optimized resource-shrinking pipeline that unifies code optimization and resource shrinking. R8 now processes code and resource references simultaneously, enabling removal of resources referenced only by unused code and eliminating unconditional keep rules generated by AAPT2. Previously, AAPT2 keep rules could reference unused code and block R8 from removing that code and its resources. Enabling R8 reduces DEX size; enabling resource shrinking removes unused resources in res and the resource table; optimized resource shrinking additionally removes DEX code by tracing references across the DEX and resource boundary. The pipeline is available as an opt-in in AGP 8.12.0.
Read at InfoQ
Unable to calculate read time
[
|
]