Commit 6fe841a9 authored by Andrey Kosyakov's avatar Andrey Kosyakov Committed by Commit Bot

Revert "Android: Link against apk_under_test resources for test apks"

This reverts commit a00b988e.

Reason for revert: speculative revert as a possible cause of android build failures (https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket.appspot.com/8916352597455843616/+/steps/compile/0/stdout)

Original change's description:
> Android: Link against apk_under_test resources for test apks
> 
> Test apks are allowed to reference resources that live in the apk_under_test.
> We've previous supported such references via R.java constants, but this
> CL also adds the ability for resources in the test apk to directly
> reference resources in the apk_under_test (e.g. via xml @references).
> 
> The need for this has come with the latest version of the support
> library.
> 
> To accomplish this:
> 1. Adds a "-I UnderTest.ap_" flag when compiling test apks resources
> 2. Sets the test apk's arsc package name to match the apk_under_test's
>    package name.
> 3. Uses --emit-ids / --stable-ids to avoid collisions between the
>    test apk and the apk_under_test.
> 4. Updates incremental install manifest logic to do the same trick.
> 
> Some other small tweaks to related resource code:
> * Removes incremental AndroidManifest.xml as an explicit build output
> * Moves most uses of "aapt dump" to "aapt2 dump"
> * Removes --check-resources-pkg-id in favor of always enabling it
> * Removes --optimize-resources in favor of having it implicitly set by
>   --optimized-resources-path
> 
> Bug: 896775
> Change-Id: I6ea2d1ec8d1109bede4e0701eb4c7aeaa2a67503
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1556395
> Commit-Queue: Andrew Grieve <agrieve@chromium.org>
> Reviewed-by: Eric Stevenson <estevenson@chromium.org>
> Reviewed-by: Tibor Goldschwendt <tiborg@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#650427}

TBR=agrieve@chromium.org,estevenson@chromium.org,tiborg@chromium.org

Change-Id: Ie70c31177c5b5e33d830a9d4fc57f10613fc5d30
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 896775
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1566365Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Commit-Queue: Andrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650453}
parent acb504b2
This diff is collapsed.
......@@ -36,9 +36,6 @@ def _ParseArgs(args):
"""
parser, input_opts, output_opts = resource_utils.ResourceArgsParser()
input_opts.add_argument(
'--aapt-path', required=True, help='Path to the Android aapt tool')
input_opts.add_argument('--resource-dirs',
default='[]',
help='A list of input directories containing resources '
......
......@@ -8,7 +8,6 @@ import contextlib
import os
import re
import shutil
import subprocess
import sys
import tempfile
from xml.etree import ElementTree
......@@ -25,8 +24,6 @@ from jinja2 import Template # pylint: disable=F0401
EMPTY_ANDROID_MANIFEST_PATH = os.path.join(
_SOURCE_ROOT, 'build', 'android', 'AndroidManifest.xml')
ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android'
TOOLS_NAMESPACE = 'http://schemas.android.com/tools'
# A variation of these maps also exists in:
# //base/android/java/src/org/chromium/base/LocaleUtils.java
......@@ -47,9 +44,6 @@ _ANDROID_TO_CHROMIUM_LANGUAGE_MAP = {
}
_xml_namespace_initialized = False
def ToAndroidLocaleName(chromium_locale):
"""Convert an Chromium locale name into a corresponding Android one."""
# First handle the special cases, these are needed to deal with Android
......@@ -517,33 +511,8 @@ public final class R {
def ExtractPackageFromManifest(manifest_path):
"""Extract package name from Android manifest file."""
return ParseAndroidManifest(manifest_path)[1].get('package')
def ExtractBinaryManifestValues(aapt2_path, apk_path):
"""Returns (version_code, version_name, package_name) for the given apk."""
output = subprocess.check_output([
aapt2_path, 'dump', 'xmltree', apk_path, '--file', 'AndroidManifest.xml'
])
version_code = re.search(r'versionCode.*?=(\d*)', output).group(1)
version_name = re.search(r'versionName.*?="(.*?)"', output).group(1)
package_name = re.search(r'package.*?="(.*?)"', output).group(1)
return version_code, version_name, package_name
def ExtractArscPackage(aapt2_path, apk_path):
"""Returns (package_name, package_id) of resources.arsc from apk_path."""
proc = subprocess.Popen([aapt2_path, 'dump', 'resources', apk_path],
stdout=subprocess.PIPE)
for line in proc.stdout:
# Package name=org.chromium.webview_shell id=7f
if line.startswith('Package'):
proc.kill()
parts = line.split()
package_name = parts[1].split('=')[1]
package_id = parts[2][3:]
return package_name, int(package_id, 16)
raise Exception('Failed to find arsc package name')
doc = ElementTree.parse(manifest_path)
return doc.getroot().get('package')
def ExtractDeps(dep_zips, deps_dir):
......@@ -634,6 +603,13 @@ def ResourceArgsParser():
help='Paths to arsc resource files used to link '
'against. Can be specified multiple times.')
input_opts.add_argument('--aapt-path', required=True,
help='Path to the Android aapt tool')
input_opts.add_argument('--aapt2-path',
help='Path to the Android aapt2 tool. If in different'
' directory from --aapt-path.')
input_opts.add_argument('--dependencies-res-zips', required=True,
help='Resources zip archives from dependents. Required to '
'resolve @type/foo references into dependent '
......@@ -654,6 +630,15 @@ def ResourceArgsParser():
'list of resources to be included in the R.java file in the format '
'generated by aapt.')
input_opts.add_argument(
'--package-name',
help='Package name that will be used to determine package ID.')
input_opts.add_argument(
'--package-name-to-id-mapping',
help='List containing mapping from package name to package IDs that will '
'be assigned.')
return (parser, input_opts, output_opts)
......@@ -686,6 +671,9 @@ def HandleCommonOptions(options):
else:
options.extra_r_text_files = []
if not options.aapt2_path:
options.aapt2_path = options.aapt_path + '2'
def ParseAndroidResourceStringsFromXml(xml_data):
"""Parse and Android xml resource file and extract strings from it.
......@@ -794,36 +782,3 @@ def FilterAndroidResourceStringsXml(xml_file_path, string_predicate):
new_xml_data = GenerateAndroidResourceStringsXml(strings_map, namespaces)
with open(xml_file_path, 'wb') as f:
f.write(new_xml_data)
def _RegisterElementTreeNamespaces():
global _xml_namespace_initialized
if not _xml_namespace_initialized:
_xml_namespace_initialized = True
ElementTree.register_namespace('android', ANDROID_NAMESPACE)
ElementTree.register_namespace('tools', TOOLS_NAMESPACE)
def ParseAndroidManifest(path):
"""Parses an AndroidManifest.xml using ElementTree.
Registers required namespaces & creates application node if missing.
Returns tuple of:
doc: Root xml document.
manifest_node: the <manifest> node.
app_node: the <application> node.
"""
_RegisterElementTreeNamespaces()
doc = ElementTree.parse(path)
# ElementTree.find does not work if the required tag is the root.
if doc.getroot().tag == 'manifest':
manifest_node = doc.getroot()
else:
manifest_node = doc.find('manifest')
app_node = doc.find('application')
if app_node is None:
app_node = ElementTree.SubElement(manifest_node, 'application')
return doc, manifest_node, app_node
......@@ -1075,9 +1075,9 @@ def main(argv):
if options.type == 'android_apk' and options.tested_apk_config:
tested_apk_deps = Deps([options.tested_apk_config])
tested_apk_config = tested_apk_deps.Direct()[0]
tested_apk_name = tested_apk_deps.Direct()[0]['name']
tested_apk_resources_deps = tested_apk_deps.All('android_resources')
gradle['apk_under_test'] = tested_apk_config['name']
gradle['apk_under_test'] = tested_apk_name
all_resources_deps = [
d for d in all_resources_deps if not d in tested_apk_resources_deps]
......@@ -1274,9 +1274,6 @@ def main(argv):
config['resources']['dependency_zips'] = dependency_zips
config['resources']['extra_package_names'] = extra_package_names
config['resources']['extra_r_text_files'] = extra_r_text_files
if options.type == 'android_apk' and options.tested_apk_config:
config['resources']['arsc_package_name'] = (
tested_apk_config['package_name'])
if is_apk_or_module_target:
deps_dex_files = [c['dex_path'] for c in all_library_deps]
......@@ -1469,6 +1466,8 @@ def main(argv):
# apk-under-test still has all of its code in its classes.dex, none of it is
# used at runtime because the copy of it within the test apk takes precidence.
if options.type == 'android_apk' and options.tested_apk_config:
tested_apk_config = GetDepConfig(options.tested_apk_config)
if tested_apk_config['proguard_enabled']:
assert options.proguard_enabled, ('proguard must be enabled for '
'instrumentation apks if it\'s enabled for the tested apk.')
......
......@@ -11,6 +11,8 @@ the application class changed to IncrementalApplication.
import argparse
import os
import re
import shutil
import subprocess
import sys
import tempfile
......@@ -19,7 +21,9 @@ from xml.etree import ElementTree
sys.path.append(os.path.join(os.path.dirname(__file__), os.path.pardir, 'gyp'))
from util import build_utils
from util import resource_utils
_ANDROID_NAMESPACE = 'http://schemas.android.com/apk/res/android'
ElementTree.register_namespace('android', _ANDROID_NAMESPACE)
_INCREMENTAL_APP_NAME = 'org.chromium.incrementalinstall.BootstrapApplication'
_META_DATA_APP_NAME = 'incremental-install-real-app'
......@@ -36,28 +40,32 @@ _INCREMENTAL_INSTRUMENTATION_CLASSES = [
def _AddNamespace(name):
"""Adds the android namespace prefix to the given identifier."""
return '{%s}%s' % (resource_utils.ANDROID_NAMESPACE, name)
return '{%s}%s' % (_ANDROID_NAMESPACE, name)
def _ParseArgs(args):
parser = argparse.ArgumentParser()
parser.add_argument(
'--src-manifest', required=True, help='The main manifest of the app')
parser.add_argument('--src-manifest',
help='The main manifest of the app',
required=True)
parser.add_argument('--out-manifest',
help='The output manifest',
required=True)
parser.add_argument('--disable-isolated-processes',
help='Changes all android:isolatedProcess to false. '
'This is required on Android M+',
action='store_true')
parser.add_argument(
'--out-apk', required=True, help='Path to output .ap_ file')
parser.add_argument(
'--in-apk', required=True, help='Path to non-incremental .ap_ file')
parser.add_argument(
'--aapt2-path', required=True, help='Path to the Android aapt tool')
parser.add_argument(
'--android-sdk-jars', help='GN List of resource apks to include.')
parser.add_argument('--out-apk', help='Path to output .ap_ file')
parser.add_argument('--in-apk', help='Path to non-incremental .ap_ file')
parser.add_argument('--aapt-path', help='Path to the Android aapt tool')
parser.add_argument('--android-sdk-jars', help='Path to the Android SDK jar.')
ret = parser.parse_args(build_utils.ExpandFileArgs(args))
if ret.out_apk and not (ret.in_apk and ret.aapt_path
and ret.android_sdk_jars):
parser.error(
'--out-apk requires --in-apk, --aapt-path, and --android-sdk-jars.')
ret.android_sdk_jars = build_utils.ParseGnList(ret.android_sdk_jars)
return ret
......@@ -67,20 +75,33 @@ def _CreateMetaData(parent, name, value):
meta_data_node.set(_AddNamespace('value'), value)
def _ProcessManifest(path, arsc_package_name, disable_isolated_processes):
doc, manifest_node, app_node = resource_utils.ParseAndroidManifest(path)
def _ProcessManifest(main_manifest, disable_isolated_processes):
"""Returns a transformed AndroidManifest.xml for use with _incremental apks.
Args:
main_manifest: Manifest contents to transform.
disable_isolated_processes: Whether to set all isolatedProcess attributes to
false
Returns:
The transformed AndroidManifest.xml.
"""
if disable_isolated_processes:
main_manifest = main_manifest.replace('isolatedProcess="true"',
'isolatedProcess="false"')
# Disable check for page-aligned native libraries.
main_manifest = main_manifest.replace('extractNativeLibs="false"',
'extractNativeLibs="true"')
# Ensure the manifest package matches that of the apk's arsc package
# So that resource references resolve correctly. The actual manifest
# package name is set via --rename-manifest-package.
manifest_node.set('package', arsc_package_name)
doc = ElementTree.fromstring(main_manifest)
app_node = doc.find('application')
if app_node is None:
app_node = ElementTree.SubElement(doc, 'application')
# Pylint for some reason things app_node is an int.
# pylint: disable=no-member
real_app_class = app_node.get(_AddNamespace('name'),
_DEFAULT_APPLICATION_CLASS)
app_node.set(_AddNamespace('name'), _INCREMENTAL_APP_NAME)
# pylint: enable=no-member
_CreateMetaData(app_node, _META_DATA_APP_NAME, real_app_class)
# Seems to be a bug in ElementTree, as doc.find() doesn't work here.
......@@ -94,46 +115,45 @@ def _ProcessManifest(path, arsc_package_name, disable_isolated_processes):
_CreateMetaData(app_node, _META_DATA_INSTRUMENTATION_NAMES[i],
real_instrumentation_class)
ret = ElementTree.tostring(doc.getroot(), encoding='UTF-8')
# Disable check for page-aligned native libraries.
ret = ret.replace('extractNativeLibs="false"', 'extractNativeLibs="true"')
if disable_isolated_processes:
ret = ret.replace('isolatedProcess="true"', 'isolatedProcess="false"')
return ret
return ElementTree.tostring(doc, encoding='UTF-8')
def main(raw_args):
options = _ParseArgs(raw_args)
def _ExtractVersionFromApk(aapt_path, apk_path):
output = subprocess.check_output([aapt_path, 'dump', 'badging', apk_path])
version_code = re.search(r"versionCode='(.*?)'", output).group(1)
version_name = re.search(r"versionName='(.*?)'", output).group(1)
return version_code, version_name,
arsc_package, _ = resource_utils.ExtractArscPackage(options.aapt2_path,
options.in_apk)
# Extract version from the compiled manifest since it might have been set
# via aapt, and not exist in the manifest's text form.
version_code, version_name, manifest_package = (
resource_utils.ExtractBinaryManifestValues(options.aapt2_path,
options.in_apk))
new_manifest_data = _ProcessManifest(options.src_manifest, arsc_package,
def main(raw_args):
options = _ParseArgs(raw_args)
with open(options.src_manifest) as f:
main_manifest_data = f.read()
new_manifest_data = _ProcessManifest(main_manifest_data,
options.disable_isolated_processes)
with tempfile.NamedTemporaryFile() as tmp_manifest, \
tempfile.NamedTemporaryFile() as tmp_apk:
tmp_manifest.write(new_manifest_data)
tmp_manifest.flush()
cmd = [
options.aapt2_path, 'link', '-o', tmp_apk.name, '--manifest',
tmp_manifest.name, '-I', options.in_apk, '--replace-version',
'--version-code', version_code, '--version-name', version_name,
'--rename-manifest-package', manifest_package, '--debug-mode'
]
for j in options.android_sdk_jars:
cmd += ['-I', j]
subprocess.check_call(cmd)
with zipfile.ZipFile(options.out_apk, 'w') as z:
path_transform = lambda p: None if p != 'AndroidManifest.xml' else p
build_utils.MergeZips(z, [tmp_apk.name], path_transform=path_transform)
path_transform = lambda p: None if p == 'AndroidManifest.xml' else p
build_utils.MergeZips(z, [options.in_apk], path_transform=path_transform)
with open(options.out_manifest, 'w') as f:
f.write(new_manifest_data)
if options.out_apk:
version_code, version_name = _ExtractVersionFromApk(
options.aapt_path, options.in_apk)
with tempfile.NamedTemporaryFile() as f:
cmd = [options.aapt_path, 'package', '-f', '-F', f.name,
'-M', options.out_manifest,
'-I', options.in_apk, '--replace-version',
'--version-code', version_code, '--version-name', version_name,
'--debug-mode']
for j in options.android_sdk_jars:
cmd += ['-I', j]
subprocess.check_call(cmd)
with zipfile.ZipFile(f.name, 'a') as z:
path_transform = lambda p: None if p == 'AndroidManifest.xml' else p
build_utils.MergeZips(
z, [options.in_apk], path_transform=path_transform)
shutil.copyfile(f.name, options.out_apk)
return 0
if __name__ == '__main__':
main(sys.argv[1:])
sys.exit(main(sys.argv[1:]))
# Generated by running:
# build/print_python_deps.py --root build/android/incremental_install --output build/android/incremental_install/generate_android_manifest.pydeps build/android/incremental_install/generate_android_manifest.py
../../../third_party/jinja2/__init__.py
../../../third_party/jinja2/_compat.py
../../../third_party/jinja2/bccache.py
../../../third_party/jinja2/compiler.py
../../../third_party/jinja2/defaults.py
../../../third_party/jinja2/environment.py
../../../third_party/jinja2/exceptions.py
../../../third_party/jinja2/filters.py
../../../third_party/jinja2/idtracking.py
../../../third_party/jinja2/lexer.py
../../../third_party/jinja2/loaders.py
../../../third_party/jinja2/nodes.py
../../../third_party/jinja2/optimizer.py
../../../third_party/jinja2/parser.py
../../../third_party/jinja2/runtime.py
../../../third_party/jinja2/tests.py
../../../third_party/jinja2/utils.py
../../../third_party/jinja2/visitor.py
../../../third_party/markupsafe/__init__.py
../../../third_party/markupsafe/_compat.py
../../../third_party/markupsafe/_native.py
../../gn_helpers.py
../gyp/util/__init__.py
../gyp/util/build_utils.py
../gyp/util/md5_check.py
../gyp/util/resource_utils.py
generate_android_manifest.py
......@@ -207,7 +207,7 @@ def _NormalizeResourcesArsc(apk_path, num_arsc_files, num_translations,
print('Skipping resources.arsc normalization (output directory required)')
return 0
ap_name = os.path.basename(apk_path).replace('.apk', '.intermediate.ap_')
ap_path = os.path.join(out_dir, 'arsc/apks', ap_name)
ap_path = os.path.join(out_dir, 'gen/arsc/apks', ap_name)
if not os.path.exists(ap_path):
raise Exception('Missing expected file: %s, try rebuilding.' % ap_path)
apk_path = ap_path
......
......@@ -877,6 +877,7 @@ template("stack_script") {
if (enable_java_templates) {
android_sdk_jar = "$android_sdk/android.jar"
android_default_aapt_path = "$android_sdk_build_tools/aapt"
android_default_aapt2_path = "$android_sdk_build_tools/aapt2"
template("android_lint") {
action_with_pydeps(target_name) {
......@@ -2085,15 +2086,6 @@ if (enable_java_templates) {
# used to determine which package ID to assign if package_name variable
# was passed in.
#
# package_id: (optional)
# Use a custom package ID in resource IDs (same purpose as
# package_name_to_id_mapping)
#
# arsc_package_name: (optional)
# Use this package name in the arsc file rather than the package name
# found in the AndroidManifest.xml. Does not affect the package name
# used in AndroidManifest.xml.
#
# Output variables:
# output: Path to a zip file containing the compiled resources.
#
......@@ -2169,6 +2161,8 @@ if (enable_java_templates) {
"--depfile",
rebase_path(depfile, root_build_dir),
"--include-resources=@FileArg($_rebased_build_config:android:sdk_jars)",
"--aapt-path",
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)",
......@@ -2182,6 +2176,12 @@ if (enable_java_templates) {
rebase_path(invoker.android_manifest, root_build_dir),
]
if (defined(invoker.package_name_to_id_mapping)) {
args += [
"--package-name-to-id-mapping=${invoker.package_name_to_id_mapping}",
]
}
if (defined(invoker.no_xml_namespaces) && invoker.no_xml_namespaces) {
args += [ "--no-xml-namespaces" ]
}
......@@ -2212,13 +2212,8 @@ if (enable_java_templates) {
]
}
if (defined(invoker.optimized_resources_path)) {
args += [
"--optimized-resources-path",
rebase_path(invoker.optimized_resources_path, root_build_dir),
]
outputs += [ invoker.optimized_resources_path ]
if (defined(invoker.optimize_resources) && invoker.optimize_resources) {
args += [ "--optimize-resources" ]
if (defined(invoker.resources_config_path)) {
inputs += [ invoker.resources_config_path ]
args += [
......@@ -2226,6 +2221,14 @@ if (enable_java_templates) {
rebase_path(invoker.resources_config_path, root_build_dir),
]
}
if (defined(invoker.unoptimized_resources_path)) {
args += [
"--unoptimized-resources-path",
rebase_path(invoker.unoptimized_resources_path, root_build_dir),
]
outputs += [ invoker.unoptimized_resources_path ]
}
}
# Useful to have android:debuggable in the manifest even for Release
......@@ -2267,26 +2270,21 @@ if (enable_java_templates) {
# generated resources table is correct. It should be 0x02 for runtime
# shared libraries, and 0x7f otherwise.
_expected_resources_pkg_id = "0x7f"
if (defined(invoker.shared_resources) && invoker.shared_resources) {
args += [ "--shared-resources" ]
}
if (defined(invoker.app_as_shared_lib) && invoker.app_as_shared_lib) {
_expected_resources_pkg_id = "0x02"
} else if (defined(invoker.app_as_shared_lib) &&
invoker.app_as_shared_lib) {
args += [ "--app-as-shared-lib" ]
}
if (defined(invoker.package_id)) {
args += [ "--package-id=${invoker.package_id}" ]
}
if (defined(invoker.package_name)) {
args += [
"--package-name=${invoker.package_name}",
"--package-name-to-id-mapping=${invoker.package_name_to_id_mapping}",
]
}
if (defined(invoker.arsc_package_name)) {
args += [
"--arsc-package-name",
invoker.arsc_package_name,
]
# NOTE: It is not possible to check the resources package ID of
# proto-compiled APKs at the moment.
if (!_proto_format) {
args += [ "--check-resources-pkg-id=$_expected_resources_pkg_id" ]
} else {
assert(_expected_resources_pkg_id != "") # Mark as used.
}
if (defined(invoker.shared_resources_whitelist)) {
......@@ -2353,6 +2351,10 @@ if (enable_java_templates) {
args += invoker.args
}
if (defined(invoker.package_name)) {
args += [ "--package-name=${invoker.package_name}" ]
}
if (defined(invoker.emit_ids_out_path)) {
outputs += [ invoker.emit_ids_out_path ]
_rebased_emit_ids_path =
......@@ -2676,6 +2678,7 @@ if (enable_java_templates) {
"assets_build_config",
"native_lib_placeholders",
"native_libs_filearg",
"packaged_resources_path",
"secondary_native_lib_placeholders",
"secondary_abi_native_libs_filearg",
"secondary_abi_loadable_modules",
......@@ -2686,12 +2689,6 @@ if (enable_java_templates) {
if (!defined(uncompress_shared_libraries)) {
uncompress_shared_libraries = _load_library_from_apk
}
if (defined(invoker.optimized_resources_path)) {
packaged_resources_path = invoker.optimized_resources_path
not_needed(invoker, [ "packaged_resources_path" ])
} else {
packaged_resources_path = invoker.packaged_resources_path
}
deps = _deps
native_libs = _native_libs + _native_libs_even_when_incremental
keystore_path = _keystore_path
......@@ -2720,6 +2717,16 @@ if (enable_java_templates) {
_incremental_compiled_resources_path = "${_base_path}_incremental.ap_"
_incremental_compile_resources_target_name =
"${target_name}_incremental__compile_resources"
_incremental_android_manifest =
get_label_info(_incremental_compile_resources_target_name,
"target_gen_dir") + "/AndroidManifest.xml"
if (defined(invoker.unoptimized_resources_path)) {
_incremental_packaged_resources_path =
invoker.unoptimized_resources_path
} else {
_incremental_packaged_resources_path = invoker.packaged_resources_path
}
_rebased_build_config =
rebase_path(invoker.assets_build_config, root_build_dir)
......@@ -2731,21 +2738,26 @@ if (enable_java_templates) {
inputs = [
_android_manifest,
invoker.assets_build_config,
invoker.packaged_resources_path,
_incremental_packaged_resources_path,
]
outputs = [
# Output the non-compiled manifest for easy debugging (as opposed to
# generating to a temp file).
_incremental_android_manifest,
_incremental_compiled_resources_path,
]
args = [
"--src-manifest",
rebase_path(_android_manifest, root_build_dir),
"--out-manifest",
rebase_path(_incremental_android_manifest, root_build_dir),
"--in-apk",
rebase_path(invoker.packaged_resources_path, root_build_dir),
rebase_path(_incremental_packaged_resources_path, root_build_dir),
"--out-apk",
rebase_path(_incremental_compiled_resources_path, root_build_dir),
"--aapt2-path",
rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir),
"--aapt-path",
rebase_path(android_default_aapt_path, root_build_dir),
"--android-sdk-jars=@FileArg($_rebased_build_config:android:sdk_jars)",
]
if (disable_incremental_isolated_processes) {
......
......@@ -2090,35 +2090,16 @@ if (enable_java_templates) {
_final_apk_path_no_ext = _final_apk_path_no_ext_list[0]
assert(_final_apk_path_no_ext != "") # Mark as used.
# Non-base bundle modules create only proto resources.
if (!_is_bundle_module || _is_base_module) {
_packaged_resources_path = "$target_out_dir/$target_name.ap_"
}
if (_is_bundle_module) {
# Path to the intermediate proto-format resources zip file.
_proto_resources_path = "$target_gen_dir/$target_name.proto.ap_"
_packaged_resources_path = "$target_gen_dir/$target_name.proto.ap_"
} else {
# resource_sizes.py needs to be able to find the unpacked resources.arsc
# file based on apk name to compute normatlized size.
_resource_sizes_arsc_path =
"$root_out_dir/arsc/" +
# file based on apk name.
_packaged_resources_path =
"$root_gen_dir/arsc/" +
rebase_path(_final_apk_path_no_ext, root_build_dir) + ".ap_"
}
_optimize_resources =
defined(invoker.optimize_resources) && invoker.optimize_resources
if (_optimize_resources) {
_optimized_resources_path = "$target_out_dir/$_template_name.optimized."
if (_is_bundle_module) {
_optimized_resources_path += ".proto.ap_"
} else {
_optimized_resources_path += ".ap_"
}
}
if (defined(invoker.apk_under_test)) {
_under_test_packaged_resource_path =
get_label_info(invoker.apk_under_test, "target_out_dir") + "/" +
get_label_info(invoker.apk_under_test, "name") + ".ap_"
}
if (defined(invoker.version_code)) {
_version_code = invoker.version_code
......@@ -2234,8 +2215,7 @@ if (enable_java_templates) {
}
}
if (_shared_libraries_is_valid ||
_secondary_abi_shared_libraries_is_valid) {
if (_shared_libraries_is_valid || _secondary_abi_shared_libraries_is_valid) {
_native_lib_version_rule = ""
if (defined(invoker.native_lib_version_rule)) {
_native_lib_version_rule = invoker.native_lib_version_rule
......@@ -2318,6 +2298,13 @@ if (enable_java_templates) {
_android_sdk_dep = "//third_party/android_sdk:android_sdk_java"
}
_optimize_resources =
defined(invoker.optimize_resources) && invoker.optimize_resources
if (_optimize_resources) {
_unoptimized_resources_path =
"$target_out_dir/$_template_name.unoptimized.ap_"
}
if (defined(invoker.shared_resources_whitelist_target)) {
_whitelist_gen_dir =
get_label_info(invoker.shared_resources_whitelist_target,
......@@ -2334,8 +2321,12 @@ if (enable_java_templates) {
_compile_resources_target = "${_template_name}__compile_resources"
_compile_resources_rtxt_out =
"${target_gen_dir}/${_compile_resources_target}_R.txt"
_compile_resources_emit_ids_out =
"${target_gen_dir}/${_compile_resources_target}.resource_ids"
_emit_resource_ids =
defined(invoker.emit_resource_ids) && invoker.emit_resource_ids
if (_emit_resource_ids) {
_compile_resources_emit_ids_out =
"${target_gen_dir}/${_compile_resources_target}.resource_ids"
}
compile_resources(_compile_resources_target) {
forward_variables_from(invoker,
[
......@@ -2362,11 +2353,18 @@ if (enable_java_templates) {
}
srcjar_path = "${target_gen_dir}/${target_name}.srcjar"
r_text_out_path = _compile_resources_rtxt_out
emit_ids_out_path = _compile_resources_emit_ids_out
if (_emit_resource_ids) {
emit_ids_out_path = _compile_resources_emit_ids_out
}
proguard_file = _generated_proguard_config
if (_enable_main_dex_list) {
proguard_file_main_dex = _generated_proguard_main_dex_config
}
output = _packaged_resources_path
if (_optimize_resources) {
optimize_resources = true
unoptimized_resources_path = _unoptimized_resources_path
}
build_config = _build_config
deps = _deps + [
......@@ -2375,22 +2373,6 @@ if (enable_java_templates) {
_android_sdk_dep,
]
if (defined(invoker.apk_under_test)) {
deps += [ "${invoker.apk_under_test}__compile_resources" ]
# Set the arsc package name to match the apk_under_test package name
# So that test resources can references under_test resources via
# @type/name syntax.
arsc_package_name =
"@FileArg($_rebased_build_config:resources:arsc_package_name)"
include_resource = _under_test_packaged_resource_path
assert(!defined(resource_ids_provider_dep))
# Passing in the --emit-ids mapping will cause aapt2 to assign resources
# IDs that do not conflict with those from apk_under_test.
resource_ids_provider_dep = invoker.apk_under_test
}
if (_is_bundle_module) {
proto_format = true
if (defined(invoker.base_module_arsc_resource_target)) {
......@@ -2398,12 +2380,6 @@ if (enable_java_templates) {
include_resource = "${invoker.base_module_arsc_resource}"
deps += [ invoker.base_module_arsc_resource_target ]
}
output = _proto_resources_path
} else {
output = _packaged_resources_path
}
if (_optimize_resources) {
optimized_resources_path = _optimized_resources_path
}
if (defined(invoker.shared_resources_whitelist_target)) {
......@@ -2413,23 +2389,6 @@ if (enable_java_templates) {
deps += [ _whitelist_deps ]
}
}
if (defined(_resource_sizes_arsc_path)) {
_copy_arsc_target = "${_template_name}__copy_arsc"
copy(_copy_arsc_target) {
deps = [
":$_compile_resources_target",
]
# resource_sizes.py doesn't care if it gets the optimized .arsc.
sources = [
_packaged_resources_path,
]
outputs = [
_resource_sizes_arsc_path,
]
}
_final_deps += [ ":$_copy_arsc_target" ]
}
if (!_is_bundle_module) {
# Output the R.txt file to a more easily discoverable location for
......@@ -2474,7 +2433,7 @@ if (enable_java_templates) {
version_name = _version_name
proto_format = false
output = _packaged_resources_path
output = "$target_gen_dir/$_template_name.arsc.ap_"
build_config = _build_config
deps = _deps + [
......@@ -2657,9 +2616,11 @@ if (enable_java_templates) {
final_dex_path = _final_dex_path
if (_is_bundle_module) {
proto_resources_path = _proto_resources_path
proto_resources_path = _packaged_resources_path
module_rtxt_path = _compile_resources_rtxt_out
} else {
}
if (!_is_bundle_module) {
apk_path = _final_apk_path
incremental_allowed = _incremental_allowed
if (_incremental_allowed) {
......@@ -2854,10 +2815,6 @@ if (enable_java_templates) {
"uncompress_dex",
])
packaged_resources_path = _packaged_resources_path
if (_optimize_resources) {
optimized_resources_path = _optimized_resources_path
}
apk_path = _final_apk_path
assets_build_config = _build_config
dex_path = _final_dex_path
......@@ -2871,6 +2828,9 @@ if (enable_java_templates) {
if (_incremental_allowed) {
android_manifest = _android_manifest
base_path = _base_path
if (_optimize_resources) {
unoptimized_resources_path = _unoptimized_resources_path
}
}
# Incremental apk does not use native libs nor final dex.
......
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