Skip to content

Extracted proguard rules do not respect priority #491

@damianw

Description

@damianw

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions