Commit bfb2f8cf authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Android: Fix dexing a prebuilt that exceeds dex limit

There was an assumption that a single prebuilt would not have more than
64k methods, but the assumption was wrong.

Bug: None
Change-Id: I4a94c383fa47ffd7f6034e094e495e98afe70c68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2027893
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarSky Malice <skym@chromium.org>
Reviewed-by: default avatarSam Maier <smaier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736561}
parent 6db34424
...@@ -273,9 +273,15 @@ def _CreateFinalDex(d8_inputs, output, tmp_dir, dex_cmd, options=None): ...@@ -273,9 +273,15 @@ def _CreateFinalDex(d8_inputs, output, tmp_dir, dex_cmd, options=None):
tmp_dex_output = os.path.join(tmp_dir, 'tmp_dex_output.zip') tmp_dex_output = os.path.join(tmp_dir, 'tmp_dex_output.zip')
if (output.endswith('.dex') if (output.endswith('.dex')
or not all(f.endswith('.dex') for f in d8_inputs)): or not all(f.endswith('.dex') for f in d8_inputs)):
if options and options.main_dex_list_path: if options:
# Provides a list of classes that should be included in the main dex file. if options.main_dex_list_path:
dex_cmd = dex_cmd + ['--main-dex-list', options.main_dex_list_path] dex_cmd = dex_cmd + ['--main-dex-list', options.main_dex_list_path]
elif options.multi_dex and int(options.min_api or 1) < 21:
# When dexing library targets, it doesn't matter what's in the main dex.
tmp_main_dex_list_path = os.path.join(tmp_dir, 'main_list.txt')
with open(tmp_main_dex_list_path, 'w') as f:
f.write('Foo.class\n')
dex_cmd = dex_cmd + ['--main-dex-list', tmp_main_dex_list_path]
tmp_dex_dir = os.path.join(tmp_dir, 'tmp_dex_dir') tmp_dex_dir = os.path.join(tmp_dir, 'tmp_dex_dir')
os.mkdir(tmp_dex_dir) os.mkdir(tmp_dex_dir)
......
...@@ -1349,6 +1349,9 @@ if (enable_java_templates) { ...@@ -1349,6 +1349,9 @@ if (enable_java_templates) {
deps += [ ":${_main_dex_list_target_name}" ] deps += [ ":${_main_dex_list_target_name}" ]
inputs += [ _main_dex_list_path ] inputs += [ _main_dex_list_path ]
} }
} else if (defined(invoker.enable_library_multidex) &&
invoker.enable_library_multidex) {
args += [ "--multi-dex" ]
} }
if (defined(invoker.input_dex_filearg)) { if (defined(invoker.input_dex_filearg)) {
...@@ -3400,9 +3403,10 @@ if (enable_java_templates) { ...@@ -3400,9 +3403,10 @@ if (enable_java_templates) {
output = _dex_path output = _dex_path
deps = [ ":$_process_prebuilt_target_name" ] deps = [ ":$_process_prebuilt_target_name" ]
# Should never need multidex when compiling individual libraries. # For library targets, we do not need a proper main dex list, but do
# Disabling multidex saves on having to create a main_dex_list. # need to allow multiple dex files.
enable_multidex = false enable_multidex = false
enable_library_multidex = true
} }
_accumulated_public_deps += [ ":${target_name}__dex" ] _accumulated_public_deps += [ ":${target_name}__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