Index: build/android/gyp/package_resources.py |
diff --git a/build/android/gyp/package_resources.py b/build/android/gyp/package_resources.py |
index 53937664c8b8de02e44bed4aba8fa29f3f3ddc25..a73d9d5831f13233b1608b7e028263613ea8d33d 100755 |
--- a/build/android/gyp/package_resources.py |
+++ b/build/android/gyp/package_resources.py |
@@ -16,9 +16,52 @@ https://android.googlesource.com/platform/sdk/+/master/files/ant/build.xml |
import optparse |
import os |
import shutil |
+import zipfile |
from util import build_utils |
+ |
+# List is generated from the chrome_apk.apk_intermediates.ap_ via: |
+# unzip -l $FILE_AP_ | cut -c31- | grep res/draw | cut -d'/' -f 2 | sort \ |
+# | uniq | grep -- -tvdpi- | cut -c10- |
+# and then manually sorted. |
+# Note that we can't just do a cross-product of dimentions because the filenames |
+# become too big and aapt fails to create the files. |
+# This leaves all default drawables (mdpi) in the main apk. Android gets upset |
+# though if any drawables are missing from the default drawables/ directory. |
+DENSITY_SPLITS = { |
+ 'hdpi': ( |
+ 'hdpi-v4', # Order matters for output file names. |
+ 'ldrtl-hdpi-v4', |
+ 'sw600dp-hdpi-v13', |
+ 'ldrtl-hdpi-v17', |
+ 'ldrtl-sw600dp-hdpi-v17', |
+ 'hdpi-v21', |
+ ), |
+ 'xhdpi': ( |
+ 'xhdpi-v4', |
+ 'ldrtl-xhdpi-v4', |
+ 'sw600dp-xhdpi-v13', |
+ 'ldrtl-xhdpi-v17', |
+ 'ldrtl-sw600dp-xhdpi-v17', |
+ 'xhdpi-v21', |
+ ), |
+ 'xxhdpi': ( |
+ 'xxhdpi-v4', |
+ 'ldrtl-xxhdpi-v4', |
+ 'sw600dp-xxhdpi-v13', |
+ 'ldrtl-xxhdpi-v17', |
+ 'ldrtl-sw600dp-xxhdpi-v17', |
+ 'xxhdpi-v21', |
+ ), |
+ 'tvdpi': ( |
+ 'tvdpi-v4', |
+ 'sw600dp-tvdpi-v13', |
+ 'ldrtl-sw600dp-tvdpi-v17', |
+ ), |
+} |
+ |
+ |
def ParseArgs(): |
"""Parses command line options. |
@@ -48,6 +91,10 @@ def ParseArgs(): |
help='directories containing assets to be packaged') |
parser.add_option('--no-compress', help='disables compression for the ' |
'given comma separated list of extensions') |
+ parser.add_option( |
+ '--create-density-splits', |
+ action='store_true', |
+ help='Enables density splits') |
parser.add_option('--apk-path', |
help='Path to output (partial) apk.') |
@@ -114,6 +161,29 @@ def PackageArgsForExtractedZip(d): |
return package_command |
+def RenameDensitySplits(apk_path): |
+ """Renames all density splits to have shorter / predictable names.""" |
+ for density, config in DENSITY_SPLITS.iteritems(): |
+ src_path = '%s_%s' % (apk_path, '_'.join(config)) |
+ dst_path = '%s-%s' % (apk_path, density) |
+ if os.path.exists(dst_path): |
+ os.unlink(dst_path) |
+ os.rename(src_path, dst_path) |
+ |
+ |
+def CheckDensityMissedConfigs(apk_path): |
+ """Raises an exception if apk_path contains any density-specifc files.""" |
+ triggers = ['-%s' % density for density in DENSITY_SPLITS] |
+ with zipfile.ZipFile(apk_path) as main_apk_zip: |
+ for name in main_apk_zip.namelist(): |
+ for trigger in triggers: |
+ if trigger in name and not 'mipmap-' in name: |
+ raise Exception(('Found density in main apk that should have been ' + |
+ 'put into a split: %s\nYou need to update ' + |
+ 'package_resources.py to include this new ' + |
+ 'config.') % name) |
+ |
+ |
def main(): |
options = ParseArgs() |
android_jar = os.path.join(options.android_sdk, 'android.jar') |
@@ -128,7 +198,6 @@ def main(): |
'--no-crunch', |
'-f', |
'--auto-add-overlay', |
- |
'-I', android_jar, |
'-F', options.apk_path, |
'--ignore-assets', build_utils.AAPT_IGNORE_PATTERN, |
@@ -152,12 +221,20 @@ def main(): |
build_utils.ExtractAll(z, path=subdir) |
package_command += PackageArgsForExtractedZip(subdir) |
+ if options.create_density_splits: |
+ for config in DENSITY_SPLITS.itervalues(): |
+ package_command.extend(('--split', ','.join(config))) |
+ |
if 'Debug' in options.configuration_name: |
package_command += ['--debug-mode'] |
build_utils.CheckOutput( |
package_command, print_stdout=False, print_stderr=False) |
+ if options.create_density_splits: |
+ CheckDensityMissedConfigs(options.apk_path) |
+ RenameDensitySplits(options.apk_path) |
+ |
if options.depfile: |
build_utils.WriteDepfile( |
options.depfile, |