Restore Proguard behavior and add minimal flag
We previously changed AAPT2 to correctly only generate keep rules for
the constructors required to inflate the different views. This cause
projects that did not have keep rules for the other constructors that
were accessed through reflection to have runtime crashes. This change
adds a flag to the link stage (--proguard-minimal-keep-rules) that
allows AAPT2 to only keep the constructors required for layout
inflation. If the flag is not present, then AAPT2 will generate less
specific keep rules than keep all constructors.
Bug: 116201243
Test: aapt2_tests
Change-Id: I8bb5cdf8446518ab153ea988e1243ca9494258c7
diff --git a/tools/aapt2/cmd/Link.h b/tools/aapt2/cmd/Link.h
index e58a93e..a42c0f2 100644
--- a/tools/aapt2/cmd/Link.h
+++ b/tools/aapt2/cmd/Link.h
@@ -49,6 +49,7 @@
Maybe<std::string> generate_proguard_rules_path;
Maybe<std::string> generate_main_dex_proguard_rules_path;
bool generate_conditional_proguard_rules = false;
+ bool generate_minimal_proguard_rules = false;
bool generate_non_final_ids = false;
std::vector<std::string> javadoc_annotations;
Maybe<std::string> private_symbols;
@@ -119,6 +120,9 @@
AddOptionalSwitch("--proguard-conditional-keep-rules",
"Generate conditional Proguard keep rules.",
&options_.generate_conditional_proguard_rules);
+ AddOptionalSwitch("--proguard-minimal-keep-rules",
+ "Generate a minimal set of Proguard keep rules.",
+ &options_.generate_minimal_proguard_rules);
AddOptionalSwitch("--no-auto-version", "Disables automatic style and layout SDK versioning.",
&options_.no_auto_version);
AddOptionalSwitch("--no-version-vectors",