Add Optimize.Protect_api_surface option
This exposes R8Command#setProtectApiSurface through the R8Wrapper.
When Optimize.Protect_api_surface is set, R8 will not add public or protected methods to API classes.
Bug: 376194365
Change-Id: Idd93b758672bb8d60d5b18e672671464072952f8
Test: existing
diff --git a/java/dex.go b/java/dex.go
index 64465a2..3df03a8 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -63,6 +63,14 @@
// Defaults to false for apps and tests, true for libraries.
Proguard_compatibility *bool
+ // If true, R8 will not add public or protected members (fields or methods) to
+ // the API surface of the compilation unit, i.e., classes that are kept or
+ // have kept subclasses will not expose any members added by R8 for internal
+ // use. That includes renamed members if obfuscation is enabled.
+ // This should only be used for building targets that go on the bootclasspath.
+ // Defaults to false.
+ Protect_api_surface *bool
+
// If true, optimize for size by removing unused code. Defaults to true for apps,
// false for libraries and tests.
Shrink *bool
@@ -390,6 +398,10 @@
r8Flags = append(r8Flags, "--force-proguard-compatibility")
}
+ if BoolDefault(opt.Protect_api_surface, false) {
+ r8Flags = append(r8Flags, "--protect-api-surface")
+ }
+
// Avoid unnecessary stack frame noise by only injecting source map ids for non-debug
// optimized or obfuscated targets.
if (Bool(opt.Optimize) || Bool(opt.Obfuscate)) && !debugMode {