javaandroidscalaproguardsbt-android-plugin

Generalization in ProGuard's "keep" arguments


ProGuard defines it's "keep" syntax here.

[@annotationtype] [[!]public|final|abstract|@ ...] [!]interface|class|enum classname
    [extends|implements [@annotationtype] classname]
[{
    [@annotationtype] [[!]public|private|protected|static|volatile|transient ...] <fields> |
                                                                      (fieldtype fieldname);
    [@annotationtype] [[!]public|private|protected|static|synchronized|native|abstract|strictfp ...] <methods> |
                                                                                           <init>(argumenttype,...) |
                                                                                           classname(argumenttype,...) |
                                                                                           (returntype methodname(argumenttype,...));
    [@annotationtype] [[!]public|private|protected|static ... ] *;
    ...
}]

Is it possible to keep use generalized modifiers and types?
For example -keep * * my.package.MySomething { *; } The 1st * would mean anything from this part: [!]public|final|abstract|@ ...], and
the 2nd * would mean anything from this part: [!]interface|class|enum.

In bit more depth, I am trying to generate ProGuard arguments dynamically and I do NOT know whether my.package.MySomething is an abstract class or public enum or anything else.

Is there a way, an option in ProGuard that could help me accomplish this?


Solution

  • The configuration

    -keep class my.package.MySomething { *; }
    

    does what you want. You'd only add access modifiers if you'd want to further constrain the matches (e.g. public; or interface instead of class).