I think a conditional approach could be a reasonable middle ground between build performance and server resource usage.
Potential strategy could be:
-
Build type: Keep using D8 for regular APK exports.
-
Size-based R8 routing for AABs: For AAB builds, we could first estimate the resulting DEX footprint from the input
.classfiles and.jardependencies.-
Since uncompressed DEX size typically compresses to ~60% of raw byte code size, if the total estimated/actual DEX footprint is under 10 MB , route through D8 (as Google Play does not enforce the 25% obfuscation threshold below 10 MB DEX size).
-
If the DEX footprint reaches or exceeds 10 MB , switch to R8 to perform code shrinking and obfuscation to satisfy the 25% threshold.
-
-
Extension/library ProGuard rules: We would also need to make sure we don't remove classes that are required by extensions or components at runtime. One option would be to automatically pick up rules from extension files such as
/files/proguard-rules.pro, if present, and also includeproguard.txtfiles packaged inside AARs.
The main goal here would be to avoid running R8 for every build, especially for smaller projects where it may not provide much benefit, while still having a path for larger apps with heavier dependencies.