Commit ebd41cb6 authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Add support for creating Bundle version of standalone/trichrome WebView

This will allow testing WebView/WebLayer behavior when using a bundle,
and will help investigate any issues that can happen.

Bug: 1033098
Change-Id: Id88c128d5dd555ccb188a172d52dcb49ee373af9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1962899Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#726589}
parent ea0e949a
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//android_webview/system_webview_apk_tmpl.gni") import("//android_webview/system_webview_apk_tmpl.gni")
import("//android_webview/system_webview_bundle.gni")
import("//android_webview/variables.gni") import("//android_webview/variables.gni")
import("//android_webview/webview_repack_locales.gni") import("//android_webview/webview_repack_locales.gni")
import("//build/android/resource_sizes.gni") import("//build/android/resource_sizes.gni")
...@@ -24,15 +25,34 @@ if (enable_resource_whitelist_generation) { ...@@ -24,15 +25,34 @@ if (enable_resource_whitelist_generation) {
} }
if (public_android_sdk) { if (public_android_sdk) {
# Standalone WebView APK. template("standalone_system_webview_apk_tmpl") {
system_webview_apk_tmpl("system_webview_apk") { system_webview_apk_tmpl(target_name) {
forward_variables_from(invoker, "*")
android_manifest = system_webview_android_manifest android_manifest = system_webview_android_manifest
android_manifest_dep = android_manifest_dep =
"//android_webview/nonembedded:system_webview_manifest" "//android_webview/nonembedded:system_webview_manifest"
deps = upstream_only_webview_deps deps = upstream_only_webview_deps
min_sdk_version = 21
}
}
# Standalone WebView APK.
standalone_system_webview_apk_tmpl("system_webview_apk") {
apk_name = "SystemWebView" apk_name = "SystemWebView"
}
if (enable_webview_bundles) {
standalone_system_webview_apk_tmpl("system_webview_base_bundle_module") {
target_type = "android_app_bundle_module"
is_base_module = true
}
system_webview_bundle("system_webview_bundle") {
base_module_target = ":system_webview_base_bundle_module"
bundle_name = "SystemWebView"
min_sdk_version = 21 min_sdk_version = 21
} }
}
android_resource_sizes_test("resource_sizes_system_webview_apk") { android_resource_sizes_test("resource_sizes_system_webview_apk") {
apk_name = "SystemWebView" apk_name = "SystemWebView"
...@@ -42,14 +62,15 @@ if (public_android_sdk) { ...@@ -42,14 +62,15 @@ if (public_android_sdk) {
} }
# Trichrome WebView APK. # Trichrome WebView APK.
system_webview_apk_tmpl("trichrome_webview_apk") { template("trichrome_webview_tmpl") {
system_webview_apk_or_module_tmpl(target_name) {
forward_variables_from(invoker, "*")
android_manifest = trichrome_webview_android_manifest android_manifest = trichrome_webview_android_manifest
android_manifest_dep = android_manifest_dep =
"//android_webview/nonembedded:trichrome_webview_manifest" "//android_webview/nonembedded:trichrome_webview_manifest"
min_sdk_version = 29 min_sdk_version = 29
deps = upstream_only_webview_deps deps = upstream_only_webview_deps
apk_name = "TrichromeWebView"
use_trichrome_library = true use_trichrome_library = true
if (android_64bit_target_cpu) { if (android_64bit_target_cpu) {
...@@ -57,15 +78,36 @@ if (public_android_sdk) { ...@@ -57,15 +78,36 @@ if (public_android_sdk) {
include_64_bit_webview = true include_64_bit_webview = true
} }
uncompress_dex = true
if (trichrome_synchronized_proguard) { if (trichrome_synchronized_proguard) {
static_library_provider = "//chrome/android:trichrome_library_apk" static_library_provider = "//chrome/android:trichrome_library_apk"
} }
} }
}
trichrome_webview_tmpl("trichrome_webview_apk") {
apk_name = "TrichromeWebView"
uncompress_dex = true
}
if (enable_webview_bundles) {
trichrome_webview_tmpl("trichrome_webview_base_bundle_module") {
target_type = "android_app_bundle_module"
is_base_module = true
}
system_webview_bundle("trichrome_webview_bundle") {
base_module_target = ":trichrome_webview_base_bundle_module"
bundle_name = "TrichromeWebView"
uncompress_dex = true
min_sdk_version = 29
}
}
# Trichrome WebView APK for a 64-bit Chrome. # Trichrome WebView APK for a 64-bit Chrome.
if (android_64bit_target_cpu) { if (android_64bit_target_cpu) {
system_webview_apk_tmpl("trichrome_webview_64_32_apk") { template("trichrome_webview_64_32_tmpl") {
system_webview_apk_or_module_tmpl(target_name) {
forward_variables_from(invoker, "*")
android_manifest = trichrome_webview_64_32_android_manifest android_manifest = trichrome_webview_64_32_android_manifest
android_manifest_dep = android_manifest_dep =
"//android_webview/nonembedded:trichrome_webview_64_32_manifest" "//android_webview/nonembedded:trichrome_webview_64_32_manifest"
...@@ -76,13 +118,32 @@ if (public_android_sdk) { ...@@ -76,13 +118,32 @@ if (public_android_sdk) {
min_sdk_version = 29 min_sdk_version = 29
deps = upstream_only_webview_deps deps = upstream_only_webview_deps
apk_name = "TrichromeWebView6432"
uncompress_dex = true
if (trichrome_synchronized_proguard) { if (trichrome_synchronized_proguard) {
static_library_provider = "//chrome/android:trichrome_library_apk" static_library_provider = "//chrome/android:trichrome_library_apk"
} }
} }
} }
trichrome_webview_64_32_tmpl("trichrome_webview_64_32_apk") {
apk_name = "TrichromeWebView6432"
uncompress_dex = true
}
if (enable_webview_bundles) {
trichrome_webview_64_32_tmpl(
"trichrome_webview_64_32_base_bundle_module") {
target_type = "android_app_bundle_module"
is_base_module = true
}
system_webview_bundle("trichrome_webview_64_32_bundle") {
base_module_target = ":trichrome_webview_64_32_base_bundle_module"
bundle_name = "TrichromeWebView6432"
uncompress_dex = true
min_sdk_version = 29
}
}
}
} }
# The shared library used by standalone WebView. # The shared library used by standalone WebView.
......
...@@ -18,10 +18,20 @@ declare_args() { ...@@ -18,10 +18,20 @@ declare_args() {
# on which you are going to install WebView is configured to load a # on which you are going to install WebView is configured to load a
# different package name than the default used in AOSP. # different package name than the default used in AOSP.
system_webview_package_name = "com.android.webview" system_webview_package_name = "com.android.webview"
# Whether to enable standalone and trichrome WebView bundle build targets.
enable_webview_bundles = false
} }
template("system_webview_apk_tmpl") { template("system_webview_apk_or_module_tmpl") {
android_apk(target_name) { if (!defined(invoker.target_type)) {
_is_bundle_module = false
_target_type = "android_apk"
} else {
_is_bundle_module = invoker.target_type == "android_app_bundle_module"
_target_type = invoker.target_type
}
target(_target_type, target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
"*", "*",
[ [
...@@ -40,7 +50,11 @@ template("system_webview_apk_tmpl") { ...@@ -40,7 +50,11 @@ template("system_webview_apk_tmpl") {
product_config_java_packages = [ webview_product_config_java_package ] product_config_java_packages = [ webview_product_config_java_package ]
if (webview_includes_weblayer) { if (webview_includes_weblayer) {
if (_is_bundle_module) {
deps += [ "//weblayer:bundle_locale_pak_assets" ]
} else {
deps += [ "//weblayer:locale_pak_assets" ] deps += [ "//weblayer:locale_pak_assets" ]
}
product_config_java_packages += [ weblayer_product_config_java_package ] product_config_java_packages += [ weblayer_product_config_java_package ]
} }
...@@ -66,7 +80,13 @@ template("system_webview_apk_tmpl") { ...@@ -66,7 +80,13 @@ template("system_webview_apk_tmpl") {
if (!_use_trichrome_library) { if (!_use_trichrome_library) {
shared_libraries = [ "//android_webview:libwebviewchromium" ] shared_libraries = [ "//android_webview:libwebviewchromium" ]
_include_primary_support = true _include_primary_support = true
if (_is_bundle_module) {
# TODO(b/146491000): aapt2 currently doesn't support the --shared-lib
# flag for bundles, so this will only work on M+.
app_as_shared_lib = true
} else {
shared_resources = true shared_resources = true
}
if (android_64bit_target_cpu) { if (android_64bit_target_cpu) {
secondary_abi_shared_libraries = [ "//android_webview:libwebviewchromium($android_secondary_abi_toolchain)" ] secondary_abi_shared_libraries = [ "//android_webview:libwebviewchromium($android_secondary_abi_toolchain)" ]
_include_secondary_support = true _include_secondary_support = true
...@@ -137,8 +157,11 @@ template("system_webview_apk_tmpl") { ...@@ -137,8 +157,11 @@ template("system_webview_apk_tmpl") {
"*.9.*", # Most nine-patches contain shadows. "*.9.*", # Most nine-patches contain shadows.
] ]
if (!_is_bundle_module) {
# Used as an additional apk in test scripts. # Used as an additional apk in test scripts.
never_incremental = true never_incremental = true
command_line_flags_file = "webview-command-line"
}
if (!is_java_debug) { if (!is_java_debug) {
proguard_enabled = true proguard_enabled = true
...@@ -159,7 +182,6 @@ template("system_webview_apk_tmpl") { ...@@ -159,7 +182,6 @@ template("system_webview_apk_tmpl") {
} }
png_to_webp = true png_to_webp = true
} }
command_line_flags_file = "webview-command-line"
if (!defined(version_code)) { if (!defined(version_code)) {
if (_use_trichrome_library) { if (_use_trichrome_library) {
...@@ -193,3 +215,11 @@ template("system_webview_apk_tmpl") { ...@@ -193,3 +215,11 @@ template("system_webview_apk_tmpl") {
} }
} }
} }
# TODO(cduvall): Remove this once src/clank uses
# system_webview_apk_or_module_tmpl.
template("system_webview_apk_tmpl") {
system_webview_apk_or_module_tmpl(target_name) {
forward_variables_from(invoker, "*")
}
}
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/rules.gni")
import("//build/config/locales.gni")
template("system_webview_bundle") {
android_app_bundle(target_name) {
command_line_flags_file = "webview-command-line"
proguard_enabled = !is_java_debug
enable_language_splits = true
system_image_locale_whitelist = locales
is_multi_abi = android_64bit_target_cpu
if (!defined(proguard_android_sdk_dep)) {
proguard_android_sdk_dep = webview_framework_dep
}
# NOTE: Only sign bundle for official builds since this is very slow.
if (enable_chrome_android_internal && use_signing_keys &&
is_official_build) {
sign_bundle = true
keystore_path = webview_keystore_path
keystore_name = webview_keystore_name
keystore_password = webview_keystore_password
}
forward_variables_from(invoker, "*")
}
}
...@@ -27,7 +27,7 @@ BUNDLETOOL_JAR_PATH = os.path.join( ...@@ -27,7 +27,7 @@ BUNDLETOOL_JAR_PATH = os.path.join(
def RunBundleTool(args): def RunBundleTool(args):
args = [build_utils.JAVA_PATH, '-jar', BUNDLETOOL_JAR_PATH] + args args = [build_utils.JAVA_PATH, '-jar', BUNDLETOOL_JAR_PATH] + args
logging.debug(' '.join(args)) logging.debug(' '.join(args))
build_utils.CheckOutput( return build_utils.CheckOutput(
args, args,
print_stdout=True, print_stdout=True,
print_stderr=True, print_stderr=True,
......
...@@ -22,6 +22,7 @@ import re ...@@ -22,6 +22,7 @@ import re
import shutil import shutil
import subprocess import subprocess
import sys import sys
import tempfile
import textwrap import textwrap
import zipfile import zipfile
from xml.etree import ElementTree from xml.etree import ElementTree
...@@ -718,7 +719,7 @@ def _PackageApk(options, build): ...@@ -718,7 +719,7 @@ def _PackageApk(options, build):
# Note: only one of --proto-format, --shared-lib or --app-as-shared-lib # Note: only one of --proto-format, --shared-lib or --app-as-shared-lib
# can be used with recent versions of aapt2. # can be used with recent versions of aapt2.
if options.shared_resources and not options.proto_path: if options.shared_resources:
link_command.append('--shared-lib') link_command.append('--shared-lib')
if options.no_xml_namespaces: if options.no_xml_namespaces:
...@@ -756,9 +757,11 @@ def _PackageApk(options, build): ...@@ -756,9 +757,11 @@ def _PackageApk(options, build):
for partial in partials: for partial in partials:
link_command += ['-R', partial] link_command += ['-R', partial]
if options.proto_path: # We always create a binary arsc file first, then convert to proto, so flags
link_command += ['--proto-format', '-o', build.proto_path] # such as --shared-lib can be supported.
else: arsc_path = build.arsc_path
if arsc_path is None:
_, arsc_path = tempfile.mkstmp()
link_command += ['-o', build.arsc_path] link_command += ['-o', build.arsc_path]
link_proc = subprocess.Popen(link_command) link_proc = subprocess.Popen(link_command)
...@@ -784,11 +787,14 @@ def _PackageApk(options, build): ...@@ -784,11 +787,14 @@ def _PackageApk(options, build):
'''.format(package=desired_manifest_package_name) '''.format(package=desired_manifest_package_name)
proguard_file.write(textwrap.dedent(keep_rule)) proguard_file.write(textwrap.dedent(keep_rule))
if options.proto_path and options.arsc_path:
build_utils.CheckOutput([ build_utils.CheckOutput([
options.aapt2_path, 'convert', '-o', build.arsc_path, build.proto_path options.aapt2_path, 'convert', '--output-format', 'proto', '-o',
build.proto_path, build.arsc_path
]) ])
if build.arsc_path is None:
os.remove(arsc_path)
if options.optimized_proto_path: if options.optimized_proto_path:
_OptimizeApk(build.optimized_proto_path, options, build.temp_dir, _OptimizeApk(build.optimized_proto_path, options, build.temp_dir,
build.proto_path, build.r_txt_path) build.proto_path, build.r_txt_path)
......
...@@ -8,7 +8,6 @@ import os ...@@ -8,7 +8,6 @@ import os
import re import re
import sys import sys
import tempfile import tempfile
import zipfile
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'gyp')) sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'gyp'))
...@@ -25,10 +24,9 @@ _ALL_ABIS = ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'] ...@@ -25,10 +24,9 @@ _ALL_ABIS = ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64']
def _CreateDeviceSpec(bundle_path, sdk_version, locales): def _CreateDeviceSpec(bundle_path, sdk_version, locales):
# Could also use "bundletool dump resources", but reading directly is faster.
if not sdk_version: if not sdk_version:
with zipfile.ZipFile(bundle_path) as f: manifest_data = bundletool.RunBundleTool(
manifest_data = f.read('base/manifest/AndroidManifest.xml') ['dump', 'manifest', '--bundle', bundle_path])
sdk_version = int( sdk_version = int(
re.search(r'minSdkVersion.*?(\d+)', manifest_data).group(1)) re.search(r'minSdkVersion.*?(\d+)', manifest_data).group(1))
......
...@@ -3681,6 +3681,9 @@ template("create_android_app_bundle_module") { ...@@ -3681,6 +3681,9 @@ template("create_android_app_bundle_module") {
if (defined(invoker.is_multi_abi) && invoker.is_multi_abi) { if (defined(invoker.is_multi_abi) && invoker.is_multi_abi) {
args += [ "--is-multi-abi" ] args += [ "--is-multi-abi" ]
} }
if (defined(invoker.uncompress_dex) && invoker.uncompress_dex) {
args += [ "--uncompress-dex" ]
}
# Use either provided dex path or build config path based on type of module. # Use either provided dex path or build config path based on type of module.
if (defined(invoker.dex_path)) { if (defined(invoker.dex_path)) {
......
...@@ -4731,7 +4731,11 @@ if (enable_java_templates) { ...@@ -4731,7 +4731,11 @@ if (enable_java_templates) {
_module_zip_path = "$target_gen_dir/$target_name/${_module.name}.zip" _module_zip_path = "$target_gen_dir/$target_name/${_module.name}.zip"
create_android_app_bundle_module(_create_module_target) { create_android_app_bundle_module(_create_module_target) {
forward_variables_from(invoker, [ "is_multi_abi" ]) forward_variables_from(invoker,
[
"is_multi_abi",
"uncompress_dex",
])
module_name = _module.name module_name = _module.name
build_config = _module_build_config build_config = _module_build_config
module_zip_path = _module_zip_path module_zip_path = _module_zip_path
......
...@@ -62,14 +62,14 @@ if (is_android) { ...@@ -62,14 +62,14 @@ if (is_android) {
[ "components_strings_{{source_name_part}}.pak" ]) [ "components_strings_{{source_name_part}}.pak" ])
} }
repack("weblayer_locales") { repack_locales("weblayer_locales") {
sources = [ input_locales = locales
"${root_gen_dir}/weblayer/components_strings_en-US.pak", output_locales = locales
] source_patterns = [ "${root_gen_dir}/weblayer/components_strings_" ]
deps = [ deps = [
":generate_components_strings", ":generate_components_strings",
] ]
output = "$root_out_dir/weblayer/locales/en-US.pak" output_dir = "$root_out_dir/weblayer/locales"
} }
android_assets("locale_pak_assets") { android_assets("locale_pak_assets") {
...@@ -81,6 +81,20 @@ if (is_android) { ...@@ -81,6 +81,20 @@ if (is_android) {
":weblayer_locales", ":weblayer_locales",
] ]
} }
android_assets("bundle_locale_pak_assets") {
disable_compression = true
renaming_sources = []
renaming_destinations = []
foreach(_locale, locales) {
renaming_sources += [ "$root_out_dir/weblayer/locales/$_locale.pak" ]
renaming_destinations += [ "locales/$_locale.pak" ]
}
treat_as_locale_paks = true
deps = [
":weblayer_locales",
]
}
} }
jumbo_static_library("weblayer_lib") { jumbo_static_library("weblayer_lib") {
......
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