Commit 85416379 authored by David 'Digit' Turner's avatar David 'Digit' Turner Committed by Commit Bot

android: More app bundle related fixes.

This CL contains a few changes related to app bundle generation.
part of a simplification of the following large CL:
https://chromium-review.googlesource.com/c/chromium/src/+/1071657

More specifically:

- bundletool.py: Enable the python script to be imported. This
  will happen in a future CL that will add new Python build
  scripts to generate app bundles and apk sets.

- Compile resources to protobuf-based format using the new
  aapt2 binary added recently to third_party/android_build_tools/.

- Add an entry in an APK's .build_config file indicating the location
  of its final dex files, to help the bundle-generating targets
  use them later.

BUG=820459
R=agrieve@chromium.org, benmason@chromium.org, yfriedman@chromium.org

Change-Id: Ifd66f11bafe804625efba3051ecf5f7c40fcf740
Reviewed-on: https://chromium-review.googlesource.com/1120530Reviewed-by: default avataragrieve <agrieve@chromium.org>
Commit-Queue: David Turner <digit@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572223}
parent ea5e1437
...@@ -14,7 +14,7 @@ import sys ...@@ -14,7 +14,7 @@ import sys
# Assume this is stored under build/android/gyp/ # Assume this is stored under build/android/gyp/
BUNDLETOOL_DIR = os.path.abspath(os.path.join( BUNDLETOOL_DIR = os.path.abspath(os.path.join(
sys.argv[0], '..', '..', '..', '..', 'third_party', 'android_build_tools', __file__, '..', '..', '..', '..', 'third_party', 'android_build_tools',
'bundletool')) 'bundletool'))
BUNDLETOOL_VERSION = '0.4.2' BUNDLETOOL_VERSION = '0.4.2'
...@@ -22,5 +22,9 @@ BUNDLETOOL_VERSION = '0.4.2' ...@@ -22,5 +22,9 @@ BUNDLETOOL_VERSION = '0.4.2'
BUNDLETOOL_JAR_PATH = os.path.join( BUNDLETOOL_JAR_PATH = os.path.join(
BUNDLETOOL_DIR, 'bundletool-all-%s.jar' % BUNDLETOOL_VERSION) BUNDLETOOL_DIR, 'bundletool-all-%s.jar' % BUNDLETOOL_VERSION)
args = ['java', '-jar', BUNDLETOOL_JAR_PATH] + sys.argv[1:] def RunBundleTool(args):
subprocess.check_call(args) args = ['java', '-jar', BUNDLETOOL_JAR_PATH] + args
subprocess.check_call(args)
if __name__ == '__main__':
RunBundleTool(sys.argv[1:])
...@@ -656,6 +656,7 @@ def main(args): ...@@ -656,6 +656,7 @@ def main(args):
possible_input_paths = [ possible_input_paths = [
options.aapt_path, options.aapt_path,
options.aapt2_path,
options.android_manifest, options.android_manifest,
options.shared_resources_whitelist, options.shared_resources_whitelist,
] ]
......
...@@ -455,7 +455,8 @@ def ResourceArgsParser(): ...@@ -455,7 +455,8 @@ def ResourceArgsParser():
help='Path to the Android aapt tool') help='Path to the Android aapt tool')
input_opts.add_argument('--aapt2-path', input_opts.add_argument('--aapt2-path',
help='Path to the Android aapt2 tool') help='Path to the Android aapt2 tool. If in different'
' directory from --aapt-path.')
input_opts.add_argument('--dependencies-res-zips', required=True, input_opts.add_argument('--dependencies-res-zips', required=True,
help='Resources zip archives from dependents. Required to ' help='Resources zip archives from dependents. Required to '
...@@ -504,3 +505,6 @@ def HandleCommonOptions(options): ...@@ -504,3 +505,6 @@ def HandleCommonOptions(options):
build_utils.ParseGnList(options.extra_r_text_files)) build_utils.ParseGnList(options.extra_r_text_files))
else: else:
options.extra_r_text_files = [] options.extra_r_text_files = []
if not options.aapt2_path:
options.aapt2_path = options.aapt_path + '2'
...@@ -342,6 +342,10 @@ to be used to load the native libraries). ...@@ -342,6 +342,10 @@ to be used to load the native libraries).
For `android_apk` and `dist_jar` targets, a list of all interface jar files For `android_apk` and `dist_jar` targets, a list of all interface jar files
that will be merged into the final `.jar` file for distribution. that will be merged into the final `.jar` file for distribution.
* `deps_info['final_dex']['path']:
Path to the final classes.dex file (or classes.zip in case of multi-dex)
for this APK.
* `deps_info['final_dex']['dependency_dex_files']`: * `deps_info['final_dex']['dependency_dex_files']`:
The list of paths to all `deps_info['dex_path']` entries for all library The list of paths to all `deps_info['dex_path']` entries for all library
dependencies for this APK. dependencies for this APK.
...@@ -860,6 +864,9 @@ def main(argv): ...@@ -860,6 +864,9 @@ def main(argv):
parser.add_option('--fail', parser.add_option('--fail',
help='GN-list of error message lines to fail with.') help='GN-list of error message lines to fail with.')
parser.add_option('--final-dex-path',
help='Path to final input classes.dex (or classes.zip) to '
'use in final apk.')
parser.add_option('--apk-proto-resources', parser.add_option('--apk-proto-resources',
help='Path to resources compiled in protocol buffer format ' help='Path to resources compiled in protocol buffer format '
' for this apk.') ' for this apk.')
...@@ -884,7 +891,8 @@ def main(argv): ...@@ -884,7 +891,8 @@ def main(argv):
jar_path_options = ['jar_path', 'unprocessed_jar_path', 'interface_jar_path'] jar_path_options = ['jar_path', 'unprocessed_jar_path', 'interface_jar_path']
required_options_map = { required_options_map = {
'android_apk': ['build_config','dex_path'] + jar_path_options, 'android_apk': ['build_config', 'dex_path', 'final_dex_path'] + \
jar_path_options,
'android_assets': ['build_config'], 'android_assets': ['build_config'],
'android_resources': ['build_config', 'resources_zip'], 'android_resources': ['build_config', 'resources_zip'],
'dist_aar': ['build_config'], 'dist_aar': ['build_config'],
...@@ -1266,6 +1274,7 @@ def main(argv): ...@@ -1266,6 +1274,7 @@ def main(argv):
config['final_dex'] = {} config['final_dex'] = {}
dex_config = config['final_dex'] dex_config = config['final_dex']
dex_config['dependency_dex_files'] = deps_dex_files dex_config['dependency_dex_files'] = deps_dex_files
dex_config['path'] = options.final_dex_path
system_jars = [c['jar_path'] for c in system_library_deps] system_jars = [c['jar_path'] for c in system_library_deps]
system_interface_jars = [c['interface_jar_path'] for c in system_library_deps] system_interface_jars = [c['interface_jar_path'] for c in system_library_deps]
......
...@@ -355,18 +355,15 @@ if (is_android || is_chromeos) { ...@@ -355,18 +355,15 @@ if (is_android || is_chromeos) {
# Dynamic app bundles ------------------------------------------------------- # Dynamic app bundles -------------------------------------------------------
# TODO(digit): Remove this once we roll a version of the Android SDK that
# has the proper build-tools binaries to both public and internal.
declare_args() { declare_args() {
# To enable generation of application bundles, define # Location of aapt2 binary used for app bundles. For now, a more recent version
# android_sdk_app_bundle_build_tools to point to an Android SDK build-tools # than the one distributed with the Android SDK is required.
# directory that has the relevant aapt2 and bundletool binaries. android_sdk_tools_bundle_aapt2 =
# "//third_party/android_build_tools/aapt2/aapt2"
android_sdk_app_bundle_build_tools = ""
}
# Whether building application bundles is supported. # Set this variable to true to enable building app bundles.
android_enable_app_bundles = android_sdk_app_bundle_build_tools != "" android_enable_app_bundles = false
}
} }
declare_args() { declare_args() {
......
...@@ -187,6 +187,12 @@ template("write_build_config") { ...@@ -187,6 +187,12 @@ template("write_build_config") {
rebase_path(invoker.dex_path, root_build_dir), rebase_path(invoker.dex_path, root_build_dir),
] ]
} }
if (defined(invoker.final_dex_path)) {
args += [
"--final-dex-path",
rebase_path(invoker.final_dex_path, root_build_dir),
]
}
if (defined(invoker.supports_android) && invoker.supports_android) { if (defined(invoker.supports_android) && invoker.supports_android) {
args += [ "--supports-android" ] args += [ "--supports-android" ]
} }
...@@ -1776,6 +1782,19 @@ if (enable_java_templates) { ...@@ -1776,6 +1782,19 @@ if (enable_java_templates) {
_srcjar_path = "${_srcjar_path}.intermediate.srcjar" _srcjar_path = "${_srcjar_path}.intermediate.srcjar"
} }
_proto_format = defined(invoker.proto_format) && invoker.proto_format
# NOTE: Regarding the names of the depfiles used by this template:
# They all have the same prefix, related to invoker.target_name,
# instead of $target_name, so it is important they have different
# file paths. Otherwise, extra-rebuilds or even incorrect builds
# may happen due to incorrect dependency information. The suffixes
# used are:
#
# _1.d for the unprocessed compiled resources.
# _2.d for the optional processed compiled resources.
# _3.d for the proto-compiled resources.
action(_compile_resources_target_name) { action(_compile_resources_target_name) {
set_sources_assignment_filter([]) set_sources_assignment_filter([])
forward_variables_from(invoker, forward_variables_from(invoker,
...@@ -1790,15 +1809,14 @@ if (enable_java_templates) { ...@@ -1790,15 +1809,14 @@ if (enable_java_templates) {
outputs = [] outputs = []
_android_aapt_path = android_default_aapt_path _android_aapt_path = android_default_aapt_path
if (defined(invoker.proto_format) && invoker.proto_format) { if (_proto_format) {
_android_aapt_path = "$android_sdk_app_bundle_build_tools/aapt" _android_aapt2_path = android_sdk_tools_bundle_aapt2
depfile = "$target_gen_dir/${invoker.target_name}_3.d"
} }
_android_aapt2_path = android_default_aapt2_path
inputs = [ inputs = [
invoker.build_config, invoker.build_config,
_android_aapt_path, _android_aapt_path,
_android_aapt2_path,
] ]
if (compute_inputs_for_analyze) { if (compute_inputs_for_analyze) {
inputs += _compile_resources_py inputs += _compile_resources_py
...@@ -1812,13 +1830,19 @@ if (enable_java_templates) { ...@@ -1812,13 +1830,19 @@ if (enable_java_templates) {
"--android-sdk-jars=@FileArg($_rebased_build_config:android:sdk_jars)", "--android-sdk-jars=@FileArg($_rebased_build_config:android:sdk_jars)",
"--aapt-path", "--aapt-path",
rebase_path(_android_aapt_path, root_build_dir), rebase_path(_android_aapt_path, root_build_dir),
"--aapt2-path",
rebase_path(_android_aapt2_path, root_build_dir),
"--dependencies-res-zips=@FileArg($_rebased_build_config:resources:dependency_zips)", "--dependencies-res-zips=@FileArg($_rebased_build_config:resources:dependency_zips)",
"--extra-res-packages=@FileArg($_rebased_build_config:resources:extra_package_names)", "--extra-res-packages=@FileArg($_rebased_build_config:resources:extra_package_names)",
"--extra-r-text-files=@FileArg($_rebased_build_config:resources:extra_r_text_files)", "--extra-r-text-files=@FileArg($_rebased_build_config:resources:extra_r_text_files)",
] ]
if (_proto_format) {
inputs += [ _android_aapt2_path ]
args += [
"--aapt2-path",
rebase_path(_android_aapt2_path, root_build_dir),
]
}
inputs += [ invoker.android_manifest ] inputs += [ invoker.android_manifest ]
args += [ args += [
"--android-manifest", "--android-manifest",
...@@ -1884,7 +1908,6 @@ if (enable_java_templates) { ...@@ -1884,7 +1908,6 @@ if (enable_java_templates) {
] ]
} }
_proto_format = defined(invoker.proto_format) && invoker.proto_format
if (_proto_format) { if (_proto_format) {
args += [ "--proto-format" ] args += [ "--proto-format" ]
} }
...@@ -2993,6 +3016,7 @@ if (enable_java_templates) { ...@@ -2993,6 +3016,7 @@ if (enable_java_templates) {
"apk_path", "apk_path",
"apk_under_test", "apk_under_test",
"extra_shared_libraries", "extra_shared_libraries",
"final_dex_path",
"incremental_allowed", "incremental_allowed",
"incremental_apk_path", "incremental_apk_path",
"incremental_install_json_path", "incremental_install_json_path",
......
...@@ -2377,6 +2377,7 @@ if (enable_java_templates) { ...@@ -2377,6 +2377,7 @@ if (enable_java_templates) {
srcjar_deps = _srcjar_deps srcjar_deps = _srcjar_deps
final_jar_path = _jar_path final_jar_path = _jar_path
dex_path = _lib_dex_path dex_path = _lib_dex_path
final_dex_path = _final_dex_path
apk_path = _final_apk_path apk_path = _final_apk_path
if (android_enable_app_bundles) { if (android_enable_app_bundles) {
......
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