diff options
| author | 2024-03-13 13:09:17 +0100 | |
|---|---|---|
| committer | 2024-03-21 12:33:53 +0100 | |
| commit | a2fa263786d4252887488fd009bd5387d50ff2fb (patch) | |
| tree | f3468ca80460eb219e2d7f14ccd3566fa732200b /java/dex.go | |
| parent | 1f4ffda2eda2bc2a459e280a26efab24ca54d61d (diff) | |
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
Diffstat (limited to 'java/dex.go')
| -rw-r--r-- | java/dex.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/java/dex.go b/java/dex.go index 4474c636a..6caaa7f48 100644 --- a/java/dex.go +++ b/java/dex.go @@ -66,6 +66,12 @@ type DexProperties struct { // If true, optimize for size by removing unused resources. Defaults to false. Shrink_resources *bool + // If true, use optimized resource shrinking in R8, overriding the + // Shrink_resources setting. Defaults to false. + // Optimized shrinking means that R8 will trace and treeshake resources together with code + // and apply additional optimizations. This implies non final fields in the R classes. + Optimized_shrink_resources *bool + // Flags to pass to proguard. Proguard_flags []string @@ -105,6 +111,10 @@ func (d *dexer) effectiveOptimizeEnabled() bool { return BoolDefault(d.dexProperties.Optimize.Enabled, d.dexProperties.Optimize.EnabledByDefault) } +func (d *DexProperties) resourceShrinkingEnabled() bool { + return BoolDefault(d.Optimize.Optimized_shrink_resources, Bool(d.Optimize.Shrink_resources)) +} + var d8, d8RE = pctx.MultiCommandRemoteStaticRules("d8", blueprint.RuleParams{ Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + @@ -351,10 +361,14 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl r8Flags = append(r8Flags, "-ignorewarnings") } + // resourcesInput is empty when we don't use resource shrinking, if on, pass these to R8 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()) + if Bool(opt.Optimized_shrink_resources) { + r8Flags = append(r8Flags, "--optimized-resource-shrinking") + } } return r8Flags, r8Deps |