Commit 87f1b6b8 authored by agrieve's avatar agrieve Committed by Commit bot

Android: Stop including unsupport locales in resources.arsc

They were being pulled in from dependent libraries. We now pass an
explicit whitelist to aapt to ensure only support locales are being
included.

This shaves 470kb off of ChromePublic.apk, 100kb of which
was recently added by the gvr library in bug 678309.

The list of removed configs (via aapt dump configurations):
af
az
az-rAZ
be-rBY
bn
bn-rBD
bs-rBA
en-rAU
en-rIN
es-r419
et
et-rEE
eu-rES
fr-rCA
gl
gl-rES
gu
gu-rIN
hy-rAM
is
is-rIS
ka
ka-rGE
kk
kk-rKZ
km
km-rKH
kn
kn-rIN
ky
ky-rKG
lo
lo-rLA
mk-rMK
ml
ml-rIN
mn
mn-rMN
mr
mr-rIN
ms
ms-rMY
my
my-rMM
ne
ne-rNP
no
pa
pa-rIN
si-rLK
sq-rAL
ta-rIN
te
te-rIN
tl
ur-rPK
uz
uz-rUZ
zh-rHK
zu

BUG=678628,678309

Review-Url: https://codereview.chromium.org/2615753004
Cr-Commit-Position: refs/heads/master@{#442907}
parent c3fd406f
......@@ -4,6 +4,7 @@
import("//build/config/android/config.gni")
import("//build/config/android/rules.gni")
import("//build/config/locales.gni")
template("system_webview_apk_tmpl") {
android_apk(target_name) {
......@@ -27,6 +28,7 @@ template("system_webview_apk_tmpl") {
if (build_apk_secondary_abi && android_64bit_target_cpu) {
secondary_abi_shared_libraries = [ "//android_webview:libwebviewchromium($android_secondary_abi_toolchain)" ]
}
aapt_locale_whitelist = locales
if (!is_java_debug) {
proguard_enabled = true
......
......@@ -31,6 +31,8 @@ public class LocaleUtils {
private static final Map<String, String> LANGUAGE_MAP_FOR_ANDROID;
static {
// A variation of this mapping also exists in:
// build/android/gyp/package_resources.py
HashMap<String, String> mapForChromium = new HashMap<>();
mapForChromium.put("iw", "he"); // Hebrew
mapForChromium.put("ji", "yi"); // Yiddish
......
......@@ -23,6 +23,22 @@ import zipfile
from util import build_utils
# A variation of this lists also exists in:
# //base/android/java/src/org/chromium/base/LocaleUtils.java
_CHROME_TO_ANDROID_LOCALE_MAP = {
'en-GB': 'en-rGB',
'en-US': 'en-rUS',
'es-419': 'es-rUS',
'fin': 'tl',
'he': 'iw',
'id': 'in',
'pt-PT': 'pt-rPT',
'pt-BR': 'pt-rBR',
'yi': 'ji',
'zh-CN': 'zh-rCN',
'zh-TW': 'zh-rTW',
}
# List is generated from the chrome_apk.apk_intermediates.ap_ via:
# unzip -l $FILE_AP_ | cut -c31- | grep res/draw | cut -d'/' -f 2 | sort \
# | uniq | grep -- -tvdpi- | cut -c10-
......@@ -113,7 +129,12 @@ def _ParseArgs(args):
help='Enables density splits')
parser.add_option('--language-splits',
default='[]',
help='GYP list of languages to create splits for')
help='GN list of languages to create splits for')
parser.add_option('--locale-whitelist',
default='[]',
help='GN list of languages to include. All other language '
'configs will be stripped out. List may include '
'a combination of Android locales or Chrome locales.')
parser.add_option('--apk-path',
help='Path to output (partial) apk.')
......@@ -132,9 +153,26 @@ def _ParseArgs(args):
options.resource_zips = build_utils.ParseGnList(options.resource_zips)
options.language_splits = build_utils.ParseGnList(options.language_splits)
options.locale_whitelist = build_utils.ParseGnList(options.locale_whitelist)
return options
def _ToAaptLocales(locale_whitelist):
"""Converts the list of Chrome locales to aapt config locales."""
ret = set()
for locale in locale_whitelist:
locale = _CHROME_TO_ANDROID_LOCALE_MAP.get(locale, locale)
if locale is None or ('-' in locale and '-r' not in locale):
raise Exception('_CHROME_TO_ANDROID_LOCALE_MAP needs updating.'
' Found: %s' % locale)
ret.add(locale)
# Always keep non-regional fall-backs.
language = locale.split('-')[0]
ret.add(language)
return sorted(ret)
def MoveImagesToNonMdpiFolders(res_root):
"""Move images from drawable-*-mdpi-* folders to drawable-* folders.
......@@ -257,6 +295,10 @@ def _ConstructMostAaptArgs(options):
if 'Debug' in options.configuration_name:
package_command += ['--debug-mode']
if options.locale_whitelist:
aapt_locales = _ToAaptLocales(options.locale_whitelist)
package_command += ['-c', ','.join(aapt_locales)]
return package_command
......
......@@ -1592,6 +1592,9 @@ if (enable_java_templates) {
outputs += [ "${invoker.resource_packaged_apk_path}_${_language}" ]
}
}
if (defined(invoker.aapt_locale_whitelist)) {
args += [ "--locale-whitelist=${invoker.aapt_locale_whitelist}" ]
}
if (defined(invoker.extensions_to_not_compress)) {
args += [
"--no-compress",
......@@ -1605,6 +1608,7 @@ if (enable_java_templates) {
package_resources_helper(_package_resources_target_name) {
forward_variables_from(invoker,
[
"aapt_locale_whitelist",
"alternative_android_sdk_jar",
"android_aapt_path",
"extensions_to_not_compress",
......@@ -1653,6 +1657,7 @@ if (enable_java_templates) {
package_resources_helper(_incremental_package_resources_target_name) {
forward_variables_from(invoker,
[
"aapt_locale_whitelist",
"alternative_android_sdk_jar",
"android_aapt_path",
"extensions_to_not_compress",
......
......@@ -1406,6 +1406,8 @@ if (enable_java_templates) {
# proguard_jar_path: The path to proguard.jar you wish to use. If undefined,
# the proguard used will be the checked in one in //third_party/proguard.
# never_incremental: If true, |incremental_apk_by_default| will be ignored.
# aapt_locale_whitelist: If set, all locales not in this list will be
# stripped from resources.arsc.
#
# Example
# android_apk("foo_apk") {
......@@ -2023,6 +2025,7 @@ if (enable_java_templates) {
create_apk("${_template_name}__create") {
forward_variables_from(invoker,
[
"aapt_locale_whitelist",
"alternative_android_sdk_jar",
"android_aapt_path",
"app_as_shared_lib",
......
......@@ -4,6 +4,7 @@
import("//base/android/linker/config.gni")
import("//build/config/android/rules.gni")
import("//build/config/locales.gni")
import("//chrome/common/features.gni")
import("//third_party/leakcanary/config.gni")
import("channel.gni")
......@@ -41,6 +42,9 @@ template("chrome_public_apk_tmpl") {
rebase_path("$root_gen_dir/CHROME_VERSION.json", root_out_dir)
native_lib_version_arg = "@FileArg($_native_lib_file:full-quoted)"
native_lib_version_rule = "//build/util:chrome_version_json"
if (!defined(aapt_locale_whitelist)) {
aapt_locale_whitelist = locales - android_chrome_omitted_locales
}
if (is_java_debug) {
enable_multidex = true
......@@ -99,6 +103,9 @@ template("monochrome_public_apk_tmpl") {
enable_relocation_packing = true
extensions_to_not_compress = ".lpak,.pak,.bin,.dat"
# Webview supports all locales (has no omitted ones).
aapt_locale_whitelist = locales
# Incremental install doesn't work for monochrome. See crbug.com/663492.
never_incremental = true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment