From 66dbc0bc32100d9696dd248018683128a1274016 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 28 Dec 2017 12:23:20 -0800 Subject: Add R8 support Add support for R8 to optimize apps and java libraries. Test: m checkbuild Change-Id: I2afd5d7a84912d3ab613c32c599bd1ebe60562e0 --- java/java.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'java/java.go') diff --git a/java/java.go b/java/java.go index f06d81d7a..106284e0c 100644 --- a/java/java.go +++ b/java/java.go @@ -191,6 +191,32 @@ type CompilerDeviceProperties struct { 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 @@ type Module struct { // 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 @@ type Module struct { // 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 @@ var ( 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 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) { 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", -- cgit v1.2.3-59-g8ed1b