in PlayAssetDelivery/BundletoolScriptSample/add_packs.py [0:0]
def main() -> None:
args = parse_args()
bundle_path = get_input_bundle_path(args)
output_path = get_output_path(args)
aapt2_bin_path = get_aapt2_bin_path(args)
sdk_jar_path = get_sdk_jar_path(args)
bundletool_path = get_bundletool_path(args)
(pack_dir, pack_names) = get_packs(args)
strip_tcf_suffixes = get_strip_tcf_suffixes(args)
compress_install_time_assets = get_compress_install_time_assets(args)
with tempfile.TemporaryDirectory() as bundle_folder:
print("Extracting input app bundle to {bundle_folder}".format(
bundle_folder=bundle_folder))
bundle_zip_path = zipfile.ZipFile(bundle_path, "r")
bundle_zip_path.extractall(path=bundle_folder)
bundle_zip_path.close()
has_upfront_pack = process_packs(pack_dir, bundle_folder, pack_names,
aapt2_bin_path, sdk_jar_path)
uses_upfront_pre_l = has_upfront_pack and get_min_sdk_version(
bundle_path, bundletool_path) < 21
bundle_config_path = extract_bundle_config(bundle_folder,
uses_upfront_pre_l,
strip_tcf_suffixes,
compress_install_time_assets)
clear_autogenerated_bundle_files(bundle_folder)
print("Parsing bundle metadata...")
metadata = parse_bundle_metadata(bundle_folder)
print("Zipping module folders...")
metadata = []
module_folders = (
module_folder for module_folder in os.listdir(bundle_folder)
if module_folder != "BUNDLE-METADATA" and
os.path.isdir(os.path.join(bundle_folder, module_folder)))
module_zip_files = [
zip_module(module_folder, bundle_folder)
for module_folder in module_folders
]
bundletool_cmd = [
"java", "-jar", bundletool_path, "build-bundle", "--modules",
",".join(module_zip_files), "--output", output_path, "--config",
bundle_config_path
]
for entry in metadata:
bundletool_cmd.append("--metadata-file")
bundletool_cmd.append(entry)
print("Running {bundletool_cmd}".format(bundletool_cmd=bundletool_cmd))
exit_code = subprocess.call(bundletool_cmd)
if exit_code != 0:
print(
"Error executing {bundletool_cmd}".format(
bundletool_cmd=bundletool_cmd),
file=sys.stderr)
sys.exit(-1)
print("Augmented app bundle is ready at {output_path}".format(
output_path=output_path))