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

Side by Side Diff: build/android/gyp/apk_obfuscate.py

Issue 1408163009: [Android] Enable multidex for debug builds of ChromePublic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix gn build Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « base/base.gyp ('k') | build/android/gyp/configure_multidex.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved. 3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Generates the obfuscated jar and test jar for an apk. 7 """Generates the obfuscated jar and test jar for an apk.
8 8
9 If proguard is not enabled or 'Release' is not in the configuration name, 9 If proguard is not enabled or 'Release' is not in the configuration name,
10 obfuscation will be a no-op. 10 obfuscation will be a no-op.
11 """ 11 """
12 12
13 import json
13 import optparse 14 import optparse
14 import os 15 import os
15 import sys 16 import sys
17 import tempfile
16 18
17 from util import build_utils 19 from util import build_utils
18 from util import proguard_util 20 from util import proguard_util
19 21
20 22
23 _PROGUARD_KEEP_CLASS = '''-keep class %s {
24 *;
25 }
26 '''
27
28
21 def ParseArgs(argv): 29 def ParseArgs(argv):
22 parser = optparse.OptionParser() 30 parser = optparse.OptionParser()
23 parser.add_option('--android-sdk', help='path to the Android SDK folder') 31 parser.add_option('--android-sdk', help='path to the Android SDK folder')
24 parser.add_option('--android-sdk-tools', 32 parser.add_option('--android-sdk-tools',
25 help='path to the Android SDK build tools folder') 33 help='path to the Android SDK build tools folder')
26 parser.add_option('--android-sdk-jar', 34 parser.add_option('--android-sdk-jar',
27 help='path to Android SDK\'s android.jar') 35 help='path to Android SDK\'s android.jar')
28 parser.add_option('--proguard-jar-path', 36 parser.add_option('--proguard-jar-path',
29 help='Path to proguard.jar in the sdk') 37 help='Path to proguard.jar in the sdk')
30 parser.add_option('--input-jars-paths', 38 parser.add_option('--input-jars-paths',
(...skipping 18 matching lines...) Expand all
49 parser.add_option('--testapp', action='store_true', 57 parser.add_option('--testapp', action='store_true',
50 help='Set this if building an instrumentation test apk') 58 help='Set this if building an instrumentation test apk')
51 parser.add_option('--tested-apk-obfuscated-jar-path', 59 parser.add_option('--tested-apk-obfuscated-jar-path',
52 help='Path to obfusctated jar of the tested apk') 60 help='Path to obfusctated jar of the tested apk')
53 parser.add_option('--test-jar-path', 61 parser.add_option('--test-jar-path',
54 help='Output path for jar containing all the test apk\'s ' 62 help='Output path for jar containing all the test apk\'s '
55 'code.') 63 'code.')
56 64
57 parser.add_option('--stamp', help='File to touch on success') 65 parser.add_option('--stamp', help='File to touch on success')
58 66
67 parser.add_option('--main-dex-list-path',
68 help='The list of classes to retain in the main dex. '
69 'These will not be obfuscated.')
70 parser.add_option('--multidex-configuration-path',
71 help='A JSON file containing multidex build configuration.')
72
59 (options, args) = parser.parse_args(argv) 73 (options, args) = parser.parse_args(argv)
60 74
61 if args: 75 if args:
62 parser.error('No positional arguments should be given. ' + str(args)) 76 parser.error('No positional arguments should be given. ' + str(args))
63 77
64 # Check that required options have been provided. 78 # Check that required options have been provided.
65 required_options = ( 79 required_options = (
66 'android_sdk', 80 'android_sdk',
67 'android_sdk_tools', 81 'android_sdk_tools',
68 'android_sdk_jar', 82 'android_sdk_jar',
(...skipping 22 matching lines...) Expand all
91 configs = build_utils.ParseGypList(options.proguard_configs) 105 configs = build_utils.ParseGypList(options.proguard_configs)
92 if options.tested_apk_obfuscated_jar_path: 106 if options.tested_apk_obfuscated_jar_path:
93 # configs should only contain the process_resources.py generated config. 107 # configs should only contain the process_resources.py generated config.
94 assert len(configs) == 1, ( 108 assert len(configs) == 1, (
95 'test apks should not have custom proguard configs: ' + str(configs)) 109 'test apks should not have custom proguard configs: ' + str(configs))
96 proguard.tested_apk_info(options.tested_apk_obfuscated_jar_path + '.info') 110 proguard.tested_apk_info(options.tested_apk_obfuscated_jar_path + '.info')
97 111
98 proguard.libraryjars([options.android_sdk_jar]) 112 proguard.libraryjars([options.android_sdk_jar])
99 proguard_injars = [p for p in input_jars if p not in exclude_paths] 113 proguard_injars = [p for p in input_jars if p not in exclude_paths]
100 proguard.injars(proguard_injars) 114 proguard.injars(proguard_injars)
115
116 multidex_config = _PossibleMultidexConfig(options)
117 if multidex_config:
118 configs.append(multidex_config)
119
101 proguard.configs(configs) 120 proguard.configs(configs)
121 proguard.CheckOutput()
102 122
103 proguard.CheckOutput() 123
124 def _PossibleMultidexConfig(options):
125 if not options.multidex_configuration_path:
126 return None
127
128 with open(options.multidex_configuration_path) as multidex_config_file:
129 multidex_config = json.loads(multidex_config_file.read())
130
131 if not (multidex_config.get('enabled') and options.main_dex_list_path):
132 return None
133
134 main_dex_list_config = ''
135 with open(options.main_dex_list_path) as main_dex_list:
136 for clazz in (l.strip() for l in main_dex_list):
137 if clazz.endswith('.class'):
138 clazz = clazz[:-len('.class')]
139 clazz = clazz.replace('/', '.')
140 main_dex_list_config += (_PROGUARD_KEEP_CLASS % clazz)
141 with tempfile.NamedTemporaryFile(
142 delete=False,
143 dir=os.path.dirname(options.main_dex_list_path),
144 prefix='main_dex_list_proguard',
145 suffix='.flags') as main_dex_config_file:
146 main_dex_config_file.write(main_dex_list_config)
147 return main_dex_config_file.name
104 148
105 149
106 def main(argv): 150 def main(argv):
107 options, _ = ParseArgs(argv) 151 options, _ = ParseArgs(argv)
108 152
109 input_jars = build_utils.ParseGypList(options.input_jars_paths) 153 input_jars = build_utils.ParseGypList(options.input_jars_paths)
110 154
111 if options.testapp: 155 if options.testapp:
112 dependency_class_filters = [ 156 dependency_class_filters = [
113 '*R.class', '*R$*.class', '*Manifest.class', '*BuildConfig.class'] 157 '*R.class', '*R$*.class', '*Manifest.class', '*BuildConfig.class']
(...skipping 15 matching lines...) Expand all
129 for f in output_files: 173 for f in output_files:
130 if os.path.exists(f): 174 if os.path.exists(f):
131 os.remove(f) 175 os.remove(f)
132 build_utils.Touch(f) 176 build_utils.Touch(f)
133 177
134 if options.stamp: 178 if options.stamp:
135 build_utils.Touch(options.stamp) 179 build_utils.Touch(options.stamp)
136 180
137 if __name__ == '__main__': 181 if __name__ == '__main__':
138 sys.exit(main(sys.argv[1:])) 182 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « base/base.gyp ('k') | build/android/gyp/configure_multidex.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698