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, 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.
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, the process for extracting the rules for each library is:
META-INF/com.android.toolsdirectory, all rules under directories with names matching the r8 version are included.META-INF/com.android.toolsdirectory, it will either includeMETA-INF/proguard.txtor everything underMETA-INF/proguard(whichever exists; it should be at max one of these, but priority is given toproguard.txtin AGP.The implementation in
rules_androidis 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.