3 # Copyright 2015 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
12 from util
import build_utils
14 sys
.path
.append(os
.path
.abspath(os
.path
.join(
15 os
.path
.dirname(__file__
), os
.pardir
)))
16 from pylib
import constants
20 parser
= argparse
.ArgumentParser()
21 parser
.add_argument('--android-sdk-tools', required
=True,
22 help='Android sdk build tools directory.')
23 parser
.add_argument('--main-dex-rules-path', action
='append', default
=[],
24 dest
='main_dex_rules_paths',
25 help='A file containing a list of proguard rules to use '
26 'in determining the class to include in the '
28 parser
.add_argument('--main-dex-list-path', required
=True,
29 help='The main dex list file to generate.')
30 parser
.add_argument('paths', nargs
='+',
31 help='JARs for which a main dex list should be '
34 args
= parser
.parse_args()
36 with
open(args
.main_dex_list_path
, 'w') as main_dex_list_file
:
38 shrinked_android_jar
= os
.path
.abspath(
39 os
.path
.join(args
.android_sdk_tools
, 'lib', 'shrinkedAndroid.jar'))
40 dx_jar
= os
.path
.abspath(
41 os
.path
.join(args
.android_sdk_tools
, 'lib', 'dx.jar'))
42 paths_arg
= ':'.join(args
.paths
)
43 rules_file
= os
.path
.abspath(
44 os
.path
.join(args
.android_sdk_tools
, 'mainDexClasses.rules'))
46 with tempfile
.NamedTemporaryFile(suffix
='.jar') as temp_jar
:
48 constants
.PROGUARD_SCRIPT_PATH
,
50 '-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify',
52 '-outjars', temp_jar
.name
,
53 '-libraryjars', shrinked_android_jar
,
54 '-include', rules_file
,
56 for m
in args
.main_dex_rules_paths
:
57 proguard_cmd
.extend(['-include', m
])
61 build_utils
.CheckOutput(proguard_cmd
)
64 'java', '-cp', dx_jar
,
65 'com.android.multidex.MainDexListBuilder',
66 temp_jar
.name
, paths_arg
68 main_dex_list
= build_utils
.CheckOutput(java_cmd
)
69 except build_utils
.CalledProcessError
as e
:
70 if 'output jar is empty' in e
.output
:
72 elif "input doesn't contain any classes" in e
.output
:
77 main_dex_list_file
.write(main_dex_list
)
82 if __name__
== '__main__':