From 038866afba8963ce4b0ad0ea3580ed90d70895d4 Mon Sep 17 00:00:00 2001 From: Artem Anashkin Date: Mon, 16 Dec 2024 17:31:55 +0300 Subject: Add AAPT flags to optimize the set of resources in the RRO apk. The solution is based on adding flags in build/soong/java/app.go. It will reduce the amount of resources in RRO. Also, it solves the problem of extra locales in the Setting and TvSettings applications (see AssetManager2.h, GetResourceLocales()). Add 3 flags: 1. "--product" - specifies a list of product names to keep. 2. "-c" - provides a list of configurations. For example, if you have dependencies on the support library, which contains translations for multiple languages, you can filter resources just for the given language configuration, like English or Spanish. 3. "--preferred-density" - allows AAPT2 to select the closest matching density and strip out all others. Change-Id: I0da8bc05f349553188264824bfa5b53c27882ee3 Signed-off-by: Artem Anashkin --- java/rro.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'java/rro.go') diff --git a/java/rro.go b/java/rro.go index ab4fafa7f..44d55646e 100644 --- a/java/rro.go +++ b/java/rro.go @@ -139,6 +139,25 @@ func (r *RuntimeResourceOverlay) GenerateAndroidBuildActions(ctx android.ModuleC r.aapt.hasNoCode = true // Do not remove resources without default values nor dedupe resource configurations with the same value aaptLinkFlags := []string{"--no-resource-deduping", "--no-resource-removal"} + + // Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided. + hasProduct := android.PrefixInList(r.aaptProperties.Aaptflags, "--product") + if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 { + aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics()) + } + + if !Bool(r.aaptProperties.Aapt_include_all_resources) { + // Product AAPT config + for _, aaptConfig := range ctx.Config().ProductAAPTConfig() { + aaptLinkFlags = append(aaptLinkFlags, "-c", aaptConfig) + } + + // Product AAPT preferred config + if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 { + aaptLinkFlags = append(aaptLinkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig()) + } + } + // Allow the override of "package name" and "overlay target package name" manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName()) if overridden || r.overridableProperties.Package_name != nil { -- cgit v1.2.3-59-g8ed1b