Skip to content

Commit

Permalink
apk_operations.py: Add --sdk-version to build-bundle-apks
Browse files Browse the repository at this point in the history
Useful to see what the .apk will look like for a specific android
version.

Change-Id: Ib294132e5c3382877d9f591751b8b58fedc12835
Reviewed-on: https://chromium-review.googlesource.com/c/1460482
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: David Turner <digit@chromium.org>
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630342}
  • Loading branch information
agrieve authored and Commit Bot committed Feb 8, 2019
1 parent 0579caa commit 9b6ce29
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
16 changes: 13 additions & 3 deletions build/android/apk_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,18 @@ def install(device):
'keystore_alias')


def _GenerateBundleApks(info, output_path, minimal=False, universal=False):
def _GenerateBundleApks(info,
output_path,
minimal=False,
minimal_sdk_version=None,
universal=False):
"""Generate an .apks archive from a bundle on demand.
Args:
info: A BundleGenerationInfo instance.
output_path: Path of output .apks archive.
minimal: Create the minimal set of apks possible (english-only).
minimal_sdk_version: When minimal=True, use this sdkVersion.
universal: Whether to create a single APK that contains the contents of all
modules.
"""
Expand All @@ -114,7 +119,8 @@ def _GenerateBundleApks(info, output_path, minimal=False, universal=False):
info.keystore_password,
info.keystore_alias,
universal=universal,
minimal=minimal)
minimal=minimal,
minimal_sdk_version=minimal_sdk_version)


def _InstallBundle(devices, bundle_apks, package_name, command_line_flags_file,
Expand Down Expand Up @@ -1425,6 +1431,9 @@ def _RegisterExtraArgs(self, group):
action='store_true',
help='Build .apks archive that targets the bundle\'s minSdkVersion and '
'contains only english splits. It still contains optional splits.')
group.add_argument(
'--sdk-version',
help='Implies --minimal. The sdkVersion to build the .apks for.')
group.add_argument('--universal', action='store_true',
help='Build .apks archive containing single APK with '
'contents of all splits. NOTE: Won\'t add modules '
Expand All @@ -1434,7 +1443,8 @@ def Run(self):
_GenerateBundleApks(
self.bundle_generation_info,
self.args.output_apks,
minimal=self.args.minimal,
minimal=self.args.sdk_version is not None or self.args.minimal,
minimal_sdk_version=self.args.sdk_version,
universal=self.args.universal)


Expand Down
17 changes: 10 additions & 7 deletions build/android/pylib/utils/app_bundle_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@
_ALL_ABIS = ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64']


def _CreateMinimalDeviceSpec(bundle_path):
def _CreateMinimalDeviceSpec(bundle_path, sdk_version):
# Could also use "bundletool dump resources", but reading directly is faster.
with zipfile.ZipFile(bundle_path) as f:
manifest_data = f.read('base/manifest/AndroidManifest.xml')
min_sdk_version = int(
re.search(r'minSdkVersion.*?(\d+)', manifest_data).group(1))
if not sdk_version:
with zipfile.ZipFile(bundle_path) as f:
manifest_data = f.read('base/manifest/AndroidManifest.xml')
sdk_version = int(
re.search(r'minSdkVersion.*?(\d+)', manifest_data).group(1))

# Setting sdkVersion=minSdkVersion prevents multiple per-minSdkVersion .apk
# files from being created within the .apks file.
return {
'screenDensity': 1000, # Ignored since we don't split on density.
'sdkVersion': min_sdk_version,
'sdkVersion': sdk_version,
'supportedAbis': _ALL_ABIS, # Our .aab files are already split on abi.
'supportedLocales': ['en'],
}
Expand All @@ -45,6 +46,7 @@ def GenerateBundleApks(bundle_path,
keystore_alias,
universal=False,
minimal=False,
minimal_sdk_version=None,
check_for_noop=True):
"""Generate an .apks archive from a an app bundle if needed.
Expand All @@ -59,11 +61,12 @@ def GenerateBundleApks(bundle_path,
universal: Whether to create a single APK that contains the contents of all
modules.
minimal: Create the minimal set of apks possible (english-only).
minimal_sdk_version: When minimal=True, use this sdkVersion.
check_for_noop: Use md5_check to short-circuit when inputs have not changed.
"""
device_spec = None
if minimal:
device_spec = _CreateMinimalDeviceSpec(bundle_path)
device_spec = _CreateMinimalDeviceSpec(bundle_path, minimal_sdk_version)

def rebuild():
logging.info('Building %s', bundle_apks_path)
Expand Down

0 comments on commit 9b6ce29

Please sign in to comment.