Use R8 for resource shrinking
We are moving the resource shinking pipeline into r8 (gennerally, not just for platform)
This disables the usage of the resource shrinker cli from cmd-line tools
Bug: 308710394
Test: Existing, validated that resource table on SystemUI was byte<>byte equal.
Change-Id: Ia36b5e5970cbdcff519a5f05d672b44dc145ea32
diff --git a/java/dex.go b/java/dex.go
index 9ce5053..cf0a94c 100644
--- a/java/dex.go
+++ b/java/dex.go
@@ -95,6 +95,8 @@
proguardDictionary android.OptionalPath
proguardConfiguration android.OptionalPath
proguardUsageZip android.OptionalPath
+ resourcesInput android.OptionalPath
+ resourcesOutput android.OptionalPath
providesTransitiveHeaderJars
}
@@ -161,7 +163,7 @@
"$r8Template": &remoteexec.REParams{
Labels: map[string]string{"type": "compile", "compiler": "r8"},
Inputs: []string{"$implicits", "${config.R8Jar}"},
- OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}"},
+ OutputFiles: []string{"${outUsage}", "${outConfig}", "${outDict}", "${resourcesOutput}"},
ExecStrategy: "${config.RER8ExecStrategy}",
ToolchainInputs: []string{"${config.JavaCmd}"},
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
@@ -181,7 +183,7 @@
Platform: map[string]string{remoteexec.PoolKey: "${config.REJavaPool}"},
},
}, []string{"outDir", "outDict", "outConfig", "outUsage", "outUsageZip", "outUsageDir",
- "r8Flags", "zipFlags", "mergeZipsFlags"}, []string{"implicits"})
+ "r8Flags", "zipFlags", "mergeZipsFlags", "resourcesOutput"}, []string{"implicits"})
func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
dexParams *compileDexParams) (flags []string, deps android.Paths) {
@@ -348,6 +350,12 @@
r8Flags = append(r8Flags, "-ignorewarnings")
}
+ if d.resourcesInput.Valid() {
+ r8Flags = append(r8Flags, "--resource-input", d.resourcesInput.Path().String())
+ r8Deps = append(r8Deps, d.resourcesInput.Path())
+ r8Flags = append(r8Flags, "--resource-output", d.resourcesOutput.Path().String())
+ }
+
return r8Flags, r8Deps
}
@@ -389,6 +397,8 @@
android.ModuleNameWithPossibleOverride(ctx), "unused.txt")
proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip")
d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip)
+ resourcesOutput := android.PathForModuleOut(ctx, "package-res-shrunken.apk")
+ d.resourcesOutput = android.OptionalPathForPath(resourcesOutput)
r8Flags, r8Deps := d.r8Flags(ctx, dexParams.flags)
r8Deps = append(r8Deps, commonDeps...)
rule := r8
@@ -407,17 +417,22 @@
rule = r8RE
args["implicits"] = strings.Join(r8Deps.Strings(), ",")
}
+ implicitOutputs := android.WritablePaths{
+ proguardDictionary,
+ proguardUsageZip,
+ proguardConfiguration}
+ if d.resourcesInput.Valid() {
+ implicitOutputs = append(implicitOutputs, resourcesOutput)
+ args["resourcesOutput"] = resourcesOutput.String()
+ }
ctx.Build(pctx, android.BuildParams{
- Rule: rule,
- Description: "r8",
- Output: javalibJar,
- ImplicitOutputs: android.WritablePaths{
- proguardDictionary,
- proguardUsageZip,
- proguardConfiguration},
- Input: dexParams.classesJar,
- Implicits: r8Deps,
- Args: args,
+ Rule: rule,
+ Description: "r8",
+ Output: javalibJar,
+ ImplicitOutputs: implicitOutputs,
+ Input: dexParams.classesJar,
+ Implicits: r8Deps,
+ Args: args,
})
} else {
d8Flags, d8Deps := d8Flags(dexParams.flags)