0

I wish to remove a class A with the following signature

package com.example

class A : Base {}

from a thirdpartylib.aar that comes with its own set of proguard/r8 rules one of which is

-keep public class * extends com.example.Base

however I wish to remove a class A since I know this wouldn't be used. How do I achieve this override.

The rule below doesn't work, since whyareyoukeeping emits the rule above.

-keep class !com.example.A

I'm trying to figure out if there is a priority to proguard rules. Is it possible to declare a rule as higher priority? Thanks in advance.

humblerookie
  • 4,717
  • 4
  • 25
  • 40

1 Answers1

4

First of all the "priority" of rules is that the most broad rule takes precedence. So if a rule keeps something it is not possible for another rule to take that keep away.

Right now the only way to override the rules included in a jar's/aar's is to fork it and replace the rules. One can do that through a local maven repository with a replacement version.

However, AGP 7.3 will include a feature for overriding rules in libraries, see https://issuetracker.google.com/37097003 for more details. It is possible to try out this through the AGP 7.3 canaries.

sgjesse
  • 3,793
  • 14
  • 17
  • Thank you so much, but is there any particular reason for generic/broader rules taking precedence? Also, what are the challenges to rule consolidation based on a precedence qualifier? like let's say `keep class !com.example.A -p 100` – humblerookie Mar 30 '22 at 08:26
  • 1
    Assuming that all libraries ship with the minimal rules needed for them to work, then all rules will have to honored. One library might need all fields of a class and another library might need a single method, so you could have `-keep class * extends I { ; }` and `-keep class ** { String toJson(); }`. TO refine these rules based on more knowledge of the app (e.g.) the `toJson` part is not used by the app is best done by replacing the rules. – sgjesse Apr 06 '22 at 12:12