Add R8 support
Add support for R8 to optimize apps and java libraries.
Test: m checkbuild
Change-Id: I2afd5d7a84912d3ab613c32c599bd1ebe60562e0
diff --git a/java/java.go b/java/java.go
index f06d81d..106284e 100644
--- a/java/java.go
+++ b/java/java.go
@@ -191,6 +191,32 @@
Profile *string
}
+ Optimize struct {
+ // If false, disable all optimization. Defaults to true for apps, false for
+ // libraries and tests.
+ Enabled *bool
+
+ // If true, optimize for size by removing unused code. Defaults to true for apps,
+ // false for libraries and tests.
+ Shrink *bool
+
+ // If true, optimize bytecode. Defaults to false.
+ Optimize *bool
+
+ // If true, obfuscate bytecode. Defaults to false.
+ Obfuscate *bool
+
+ // If true, do not use the flag files generated by aapt that automatically keep
+ // classes referenced by the app manifest. Defaults to false.
+ No_aapt_flags *bool
+
+ // Flags to pass to proguard.
+ Proguard_flags []string
+
+ // Specifies the locations of files containing proguard flags.
+ Proguard_flags_files []string
+ }
+
// When targeting 1.9, override the modules to use with --system
System_modules *string
}
@@ -216,6 +242,9 @@
// output file containing uninstrumented classes that will be instrumented by jacoco
jacocoReportClassesFile android.Path
+ // output file containing mapping of obfuscated names
+ proguardDictionary android.Path
+
// output file suitable for installing or running
outputFile android.Path
@@ -229,6 +258,9 @@
// list of .java files and srcjars that was passed to javac
compiledJavaSrcs android.Paths
compiledSrcJars android.Paths
+
+ // list of extra progurad flag files
+ extraProguardFlagFiles android.Paths
}
func (j *Module) Srcs() android.Paths {
@@ -260,6 +292,7 @@
systemModulesTag = dependencyTag{name: "system modules"}
frameworkResTag = dependencyTag{name: "framework-res"}
kotlinStdlibTag = dependencyTag{name: "kotlin-stdlib"}
+ proguardRaiseTag = dependencyTag{name: "proguard-raise"}
)
type sdkDep struct {
@@ -377,6 +410,10 @@
ctx.AddDependency(ctx.Module(), systemModulesTag, sdkDep.systemModules)
}
ctx.AddDependency(ctx.Module(), bootClasspathTag, sdkDep.module)
+ if Bool(j.deviceProperties.Optimize.Enabled) {
+ ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultBootclasspathLibraries...)
+ ctx.AddDependency(ctx.Module(), proguardRaiseTag, config.DefaultLibraries...)
+ }
}
} else if j.deviceProperties.System_modules == nil {
ctx.PropertyErrorf("no_standard_libs",