Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tighten keep rule #1494

Open
elharo opened this issue Feb 14, 2020 · 3 comments
Open

Tighten keep rule #1494

elharo opened this issue Feb 14, 2020 · 3 comments
Labels
priority: p4 type: cleanup An internal cleanup or hygiene concern.

Comments

@elharo
Copy link
Contributor

elharo commented Feb 14, 2020

See #1491

@justcla suggests we can tighten this rule so the class is not always retained.

@elharo elharo added the type: cleanup An internal cleanup or hygiene concern. label Feb 14, 2020
@justcla
Copy link

justcla commented Feb 14, 2020

I recommend using conditional keep-rules. These can be triggered based on the inclusion of specific annotations in the app's code base.

@justcla
Copy link

justcla commented Feb 14, 2020

From Unofficial R8 documentation:

-if <class-spec> <one-keep-rule>
Conditionally apply one keep rule. If class members are specified, the class and all specified members must match. Otherwise, only the class need match. Class specification in the keep rule can contain back references to wildcards in the -if class specification. (ProGuard docs -if)

eg.

-if @KeepGoogleUtils keep public class com.google.api.client.googleapis.GoogleUtils

In the example above, users who want to keep the GoogleUtils only need to include the @KeepGoogleUtils annotation somewhere in the app source code.

@justcla
Copy link

justcla commented Feb 14, 2020

If you can segment parts of the library that can be kept seprately, then you can create several different annotation. For example, if your library has a Payments section and a Mapping section and a Messaging section, and the code can be cleanly separated by package name or class names, then you could have annotations like @KeepGUtilsPayments, @KeepGUtilsMapping and @KeepGUtilsMessaging. That way the built binary doesn't need to include parts of the library that won't be used.

The keep rules that ship with the library should represent the segments.

eg.

-if @KeepGUtilsPayments keep public class com.google.api.client.googleapis.Payments
-if @KeepGUtilsMapping keep public class com.google.api.client.googleapis.Mapping
-if @KeepGUtilsMessaging keep public class com.google.api.client.googleapis.Messaging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p4 type: cleanup An internal cleanup or hygiene concern.
Projects
None yet
Development

No branches or pull requests

3 participants