Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: build/android/gyp/dex.py

Issue 1278573002: [Android] Add gyp support for multidex. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/apkbuilder_action.gypi ('k') | build/android/gyp/main_dex_list.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/dex.py
diff --git a/build/android/gyp/dex.py b/build/android/gyp/dex.py
index c26d23a61166627dba6c0acddd189301dd35c18a..3b4141f2f1418a47ff345d496ee54aaf86ae7674 100755
--- a/build/android/gyp/dex.py
+++ b/build/android/gyp/dex.py
@@ -4,21 +4,57 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import logging
import optparse
import os
import sys
+import tempfile
+import zipfile
from util import build_utils
from util import md5_check
-def DoDex(options, paths):
+def DoMultiDex(options, paths):
+ main_dex_list = []
+ main_dex_list_files = build_utils.ParseGypList(options.main_dex_list_paths)
+ for m in main_dex_list_files:
+ with open(m) as main_dex_list_file:
+ main_dex_list.extend(l for l in main_dex_list_file if l)
+
+ with tempfile.NamedTemporaryFile(suffix='.txt') as combined_main_dex_list:
+ combined_main_dex_list.write('\n'.join(main_dex_list))
+ combined_main_dex_list.flush()
+
+ dex_args = [
+ '--multi-dex',
+ '--minimal-main-dex',
+ '--main-dex-list=%s' % combined_main_dex_list.name
+ ]
+
+ DoDex(options, paths, dex_args=dex_args)
+
+ if options.dex_path.endswith('.zip'):
+ iz = zipfile.ZipFile(options.dex_path, 'r')
+ tmp_dex_path = '%s.tmp.zip' % options.dex_path
+ oz = zipfile.ZipFile(tmp_dex_path, 'w', zipfile.ZIP_DEFLATED)
+ for i in iz.namelist():
+ if i.endswith('.dex'):
+ oz.writestr(i, iz.read(i))
+ os.remove(options.dex_path)
+ os.rename(tmp_dex_path, options.dex_path)
+
+
+def DoDex(options, paths, dex_args=None):
dx_binary = os.path.join(options.android_sdk_tools, 'dx')
# See http://crbug.com/272064 for context on --force-jumbo.
dex_cmd = [dx_binary, '--dex', '--force-jumbo', '--output', options.dex_path]
if options.no_locals != '0':
dex_cmd.append('--no-locals')
+ if dex_args:
+ dex_cmd += dex_args
+
dex_cmd += paths
record_path = '%s.md5.stamp' % options.dex_path
@@ -54,9 +90,14 @@ def main():
'is enabled.'))
parser.add_option('--no-locals',
help='Exclude locals list from the dex file.')
+ parser.add_option('--multi-dex', default=False, action='store_true',
+ help='Create multiple dex files.')
parser.add_option('--inputs', help='A list of additional input paths.')
parser.add_option('--excluded-paths',
help='A list of paths to exclude from the dex file.')
+ parser.add_option('--main-dex-list-paths',
+ help='A list of paths containing a list of the classes to '
+ 'include in the main dex.')
options, paths = parser.parse_args(args)
@@ -76,7 +117,14 @@ def main():
paths = [p for p in paths if not
os.path.relpath(p, options.output_directory) in exclude_paths]
- DoDex(options, paths)
+ if options.multi_dex and options.main_dex_list_paths:
+ DoMultiDex(options, paths)
+ else:
+ if options.multi_dex:
+ logging.warning('--multi-dex is unused without --main-dex-list-paths')
+ elif options.main_dex_list_paths:
+ logging.warning('--main-dex-list-paths is unused without --multi-dex')
+ DoDex(options, paths)
if options.depfile:
build_utils.WriteDepfile(
« no previous file with comments | « build/android/apkbuilder_action.gypi ('k') | build/android/gyp/main_dex_list.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698