Search code examples
androidproguardobfuscationandroid-r8

How to override other proguard rules


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.


Solution

  • 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.