Index: build/android/gyp/apk_obfuscate.py |
diff --git a/build/android/gyp/apk_obfuscate.py b/build/android/gyp/apk_obfuscate.py |
index 286555dcd8671780292aeadd2f39cea9e605cae7..ee78d9347c39fa087b6647822d973e6437082dfd 100755 |
--- a/build/android/gyp/apk_obfuscate.py |
+++ b/build/android/gyp/apk_obfuscate.py |
@@ -10,14 +10,22 @@ If proguard is not enabled or 'Release' is not in the configuration name, |
obfuscation will be a no-op. |
""" |
+import json |
import optparse |
import os |
import sys |
+import tempfile |
from util import build_utils |
from util import proguard_util |
+_PROGUARD_KEEP_CLASS = '''-keep class %s { |
+ *; |
+} |
+''' |
+ |
+ |
def ParseArgs(argv): |
parser = optparse.OptionParser() |
parser.add_option('--android-sdk', help='path to the Android SDK folder') |
@@ -56,6 +64,12 @@ def ParseArgs(argv): |
parser.add_option('--stamp', help='File to touch on success') |
+ parser.add_option('--main-dex-list-path', |
+ help='The list of classes to retain in the main dex. ' |
+ 'These will not be obfuscated.') |
+ parser.add_option('--multidex-configuration-path', |
+ help='A JSON file containing multidex build configuration.') |
+ |
(options, args) = parser.parse_args(argv) |
if args: |
@@ -88,6 +102,11 @@ def DoProguard(options): |
library_classpath = [options.android_sdk_jar] |
input_jars = build_utils.ParseGypList(options.input_jars_paths) |
+ if options.multidex_configuration_path: |
+ with open(options.multidex_configuration_path) as multidex_config_file: |
+ multidex_config = json.loads(multidex_config_file.read()) |
+ input_jars.extend(multidex_config.get('libs', [])) |
+ |
exclude_paths = [] |
configs = build_utils.ParseGypList(options.proguard_configs) |
if options.tested_apk_obfuscated_jar_path: |
@@ -106,8 +125,24 @@ def DoProguard(options): |
proguard.libraryjars(library_classpath) |
proguard_injars = [p for p in input_jars if p not in exclude_paths] |
proguard.injars(proguard_injars) |
- proguard.configs(configs) |
+ if options.main_dex_list_path: |
Yaron
2015/11/11 02:06:38
nit: extract fn
jbudorick
2015/11/12 20:33:40
Done.
|
+ main_dex_list_config = '' |
+ with open(options.main_dex_list_path) as main_dex_list: |
+ for clazz in (l.strip() for l in main_dex_list): |
+ if clazz.endswith('.class'): |
+ clazz = clazz[:-len('.class')] |
+ clazz = clazz.replace('/', '.') |
+ main_dex_list_config += (_PROGUARD_KEEP_CLASS % clazz) |
+ with tempfile.NamedTemporaryFile( |
+ delete=False, |
+ dir=os.path.dirname(options.main_dex_list_path), |
+ prefix='main_dex_list_proguard', |
+ suffix='.flags') as main_dex_config_file: |
+ main_dex_config_file.write(main_dex_list_config) |
+ configs.append(main_dex_config_file.name) |
+ |
+ proguard.configs(configs) |
proguard.CheckOutput() |
this_info = { |