def rebuild(): logging.info('Building %s', bundle_apks_path) with tempfile.NamedTemporaryFile(suffix='.apks') as tmp_apks_file: cmd_args = [ 'build-apks', '--aapt2=%s' % aapt2_path, '--output=%s' % tmp_apks_file.name, '--bundle=%s' % bundle_path, '--ks=%s' % keystore_path, '--ks-pass=pass:%s' % keystore_password, '--ks-key-alias=%s' % keystore_alias, '--overwrite', ] if mode is not None: if mode not in BUILD_APKS_MODES: raise Exception( 'Invalid mode parameter %s (should be in %s)' % (mode, BUILD_APKS_MODES)) cmd_args += ['--mode=' + mode] with tempfile.NamedTemporaryFile(suffix='.json') as spec_file: if device_spec: json.dump(device_spec, spec_file) spec_file.flush() cmd_args += ['--device-spec=' + spec_file.name] bundletool.RunBundleTool(cmd_args) # Make the resulting .apks file hermetic. with build_utils.TempDir() as temp_dir, \ build_utils.AtomicOutput(bundle_apks_path, only_if_changed=False) as f: files = build_utils.ExtractAll(tmp_apks_file.name, temp_dir) build_utils.DoZip(files, f, base_dir=temp_dir)
def rebuild(): logging.info('Building %s', bundle_apks_path) with tempfile.NamedTemporaryFile(suffix='.json') as spec_file, \ build_utils.AtomicOutput(bundle_apks_path, only_if_changed=False) as f: cmd_args = [ 'build-apks', '--aapt2=%s' % aapt2_path, '--output=%s' % f.name, '--bundle=%s' % bundle_path, '--ks=%s' % keystore_path, '--ks-pass=pass:%s' % keystore_password, '--ks-key-alias=%s' % keystore_alias, '--overwrite', ] if device_spec: json.dump(device_spec, spec_file) spec_file.flush() cmd_args += ['--device-spec=' + spec_file.name] if mode is not None: if mode not in BUILD_APKS_MODES: raise Exception( 'Invalid mode parameter %s (should be in %s)' % (mode, BUILD_APKS_MODES)) cmd_args += ['--mode=' + mode] bundletool.RunBundleTool(cmd_args)
def rebuild(): logging.info('Building %s', bundle_apks_path) with build_utils.TempDir() as tmp_dir: tmp_apks_file = os.path.join(tmp_dir, 'output.apks') cmd_args = [ 'build-apks', '--aapt2=%s' % aapt2_path, '--output=%s' % tmp_apks_file, '--ks=%s' % keystore_path, '--ks-pass=pass:%s' % keystore_password, '--ks-key-alias=%s' % keystore_alias, '--overwrite', ] input_bundle_path = bundle_path # Work around bundletool not respecting uncompressDexFiles setting. # b/176198991 if mode not in _SYSTEM_MODES and _BundleMinSdkVersion( bundle_path) >= 27: input_bundle_path = os.path.join(tmp_dir, 'system.aab') _FixBundleDexCompressionGlob(bundle_path, input_bundle_path) cmd_args += ['--bundle=%s' % input_bundle_path] if local_testing: cmd_args += ['--local-testing'] if mode is not None: if mode not in BUILD_APKS_MODES: raise Exception( 'Invalid mode parameter %s (should be in %s)' % (mode, BUILD_APKS_MODES)) cmd_args += ['--mode=' + mode] if optimize_for: if optimize_for not in OPTIMIZE_FOR_OPTIONS: raise Exception('Invalid optimize_for parameter %s ' '(should be in %s)' % (mode, OPTIMIZE_FOR_OPTIONS)) cmd_args += ['--optimize-for=' + optimize_for] if device_spec: spec_file = os.path.join(tmp_dir, 'device.json') with open(spec_file, 'w') as f: json.dump(device_spec, f) cmd_args += ['--device-spec=' + spec_file] bundletool.RunBundleTool(cmd_args) shutil.move(tmp_apks_file, bundle_apks_path)
def _CreateDeviceSpec(bundle_path, sdk_version, locales): if not sdk_version: manifest_data = bundletool.RunBundleTool( ['dump', 'manifest', '--bundle', bundle_path]) 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': sdk_version, 'supportedAbis': _ALL_ABIS, # Our .aab files are already split on abi. 'supportedLocales': locales, }
def rebuild(): logging.info('Building %s', bundle_apks_path) with tempfile.NamedTemporaryFile(suffix='.json') as spec_file, \ build_utils.AtomicOutput(bundle_apks_path, only_if_changed=False) as f: cmd_args = [ 'build-apks', '--aapt2=%s' % aapt2_path, '--output=%s' % f.name, '--bundle=%s' % bundle_path, '--ks=%s' % keystore_path, '--ks-pass=pass:%s' % keystore_password, '--ks-key-alias=%s' % keystore_alias, '--overwrite', ] if device_spec: json.dump(device_spec, spec_file) spec_file.flush() cmd_args += ['--device-spec=' + spec_file.name] if universal: cmd_args += ['--mode=universal'] bundletool.RunBundleTool(cmd_args)
def _BundleMinSdkVersion(bundle_path): manifest_data = bundletool.RunBundleTool( ['dump', 'manifest', '--bundle', bundle_path]) return int(re.search(r'minSdkVersion.*?(\d+)', manifest_data).group(1))
def _GetManifestForModule(bundle_path, module_name): return ElementTree.fromstring( bundletool.RunBundleTool([ 'dump', 'manifest', '--bundle', bundle_path, '--module', module_name ]))