bazelbuild / bazelbuild/rules_android
Extracted proguard rules do not respect priority
- Dominant language
- Java
- Stars
- 203
- Forks
- 95
- PR merge metrics
- No merged PRs in 30d
Description
The recently-added feature of extracting Proguard rules for R8 does not respect the priority of the files on a per-library basis.
Referring to the AGP code [here](https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/internal/dependency/FilterShrinkerRulesTransform.kt;l=44-96;drc=d543753698322c13018689a84b8cf2ee54115222), the process for extracting the rules for each library is:
- If it contains the `META-INF/com.android.tools` directory, all rules under directories with names _matching the r8 version_ are included.
- If it does not contain the `META-INF/com.android.tools` directory, it will either include `META-INF/proguard.txt` or everything under `META-INF/proguard` (whichever exists; it should be at max one of these, but priority is given to `proguard.txt` in AGP).
The implementation in `rules_android` is flawed because this prioritization is not respected. In fact, it cannot be respected, because the rules are extracted from the deploy jar - in a single merged directory structure, the information about which other rules files are superceded by another is lost. For that matter, files with overlapping names will be lost too.
Respecting these rules is important for optimal R8 configuration, since the reason behind having separate rule sets is that a configuration necessary for Proguard may unnecessarily prevent optimizations in R8, or likewise between different R8 versions.
Internally we have implemented the extraction with aspects to solve this problem, and if there's consensus we'd be happy to upstream that.
Contributor guide
Assessment
This issue has not been assessed yet.