Add flag for optimized resource shrinking with R8
If the flag is set we will: - pass --optimized-resource-shrinking to the r8 invocation - use non final fields for the generated R classes - not pass the aapt2 generated proguard rules, R8 will do the tracing of xml files Bug: 325905703 Test: This is simply passing the flag through to R8, this is off by default Change-Id: Ib2043f3201578c3bcd39c1de9a524fd78f6d795c
This commit is contained in:
12
java/aar.go
12
java/aar.go
@@ -351,6 +351,7 @@ type aaptBuildActionOptions struct {
|
||||
classLoaderContexts dexpreopt.ClassLoaderContextMap
|
||||
excludedLibs []string
|
||||
enforceDefaultTargetSdkVersion bool
|
||||
forceNonFinalResourceIDs bool
|
||||
extraLinkFlags []string
|
||||
aconfigTextFiles android.Paths
|
||||
}
|
||||
@@ -544,7 +545,8 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio
|
||||
|
||||
if a.useResourceProcessorBusyBox(ctx) {
|
||||
rJar := android.PathForModuleOut(ctx, "busybox/R.jar")
|
||||
resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary, a.aaptProperties.Aaptflags)
|
||||
resourceProcessorBusyBoxGenerateBinaryR(ctx, rTxt, a.mergedManifestFile, rJar, staticDeps, a.isLibrary, a.aaptProperties.Aaptflags,
|
||||
opts.forceNonFinalResourceIDs)
|
||||
aapt2ExtractExtraPackages(ctx, extraPackages, rJar)
|
||||
transitiveRJars = append(transitiveRJars, rJar)
|
||||
a.rJar = rJar
|
||||
@@ -608,7 +610,8 @@ var resourceProcessorBusyBox = pctx.AndroidStaticRule("resourceProcessorBusyBox"
|
||||
// using Bazel's ResourceProcessorBusyBox tool, which is faster than compiling the R.java files and
|
||||
// supports producing classes for static dependencies that only include resources from that dependency.
|
||||
func resourceProcessorBusyBoxGenerateBinaryR(ctx android.ModuleContext, rTxt, manifest android.Path,
|
||||
rJar android.WritablePath, transitiveDeps transitiveAarDeps, isLibrary bool, aaptFlags []string) {
|
||||
rJar android.WritablePath, transitiveDeps transitiveAarDeps, isLibrary bool, aaptFlags []string,
|
||||
forceNonFinalIds bool) {
|
||||
|
||||
var args []string
|
||||
var deps android.Paths
|
||||
@@ -618,6 +621,9 @@ func resourceProcessorBusyBoxGenerateBinaryR(ctx android.ModuleContext, rTxt, ma
|
||||
// to ResourceProcessorBusyBox so that it can regenerate R.class files with the final resource IDs for each
|
||||
// package.
|
||||
args, deps = transitiveDeps.resourceProcessorDeps()
|
||||
if forceNonFinalIds {
|
||||
args = append(args, "--finalFields=false")
|
||||
}
|
||||
} else {
|
||||
// When compiling a library don't pass any dependencies as it only needs to generate an R.class file for this
|
||||
// library. Pass --finalFields=false so that the R.class file contains non-final fields so they don't get
|
||||
@@ -1221,7 +1227,7 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
||||
linkFlags, linkDeps, nil, overlayRes, transitiveAssets, nil, nil)
|
||||
|
||||
a.rJar = android.PathForModuleOut(ctx, "busybox/R.jar")
|
||||
resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true, nil)
|
||||
resourceProcessorBusyBoxGenerateBinaryR(ctx, a.rTxt, a.manifest, a.rJar, nil, true, nil, false)
|
||||
|
||||
aapt2ExtractExtraPackages(ctx, a.extraAaptPackagesFile, a.rJar)
|
||||
|
||||
|
Reference in New Issue
Block a user