def main(raw_args): options = _ParseArgs(raw_args) arsc_package, _ = resource_utils.ExtractArscPackage( options.aapt2_path, options.in_apk) # Extract version from the compiled manifest since it might have been set # via aapt, and not exist in the manifest's text form. version_code, version_name, manifest_package = ( resource_utils.ExtractBinaryManifestValues(options.aapt2_path, options.in_apk)) new_manifest_data = _ProcessManifest(options.src_manifest, arsc_package, options.disable_isolated_processes) with tempfile.NamedTemporaryFile() as tmp_manifest, \ tempfile.NamedTemporaryFile() as tmp_apk: tmp_manifest.write(new_manifest_data) tmp_manifest.flush() cmd = [ options.aapt2_path, 'link', '-o', tmp_apk.name, '--manifest', tmp_manifest.name, '-I', options.in_apk, '--replace-version', '--version-code', version_code, '--version-name', version_name, '--rename-manifest-package', manifest_package, '--debug-mode' ] for j in options.android_sdk_jars: cmd += ['-I', j] subprocess.check_call(cmd) with zipfile.ZipFile(options.out_apk, 'w') as z: path_transform = lambda p: None if p != 'AndroidManifest.xml' else p build_utils.MergeZips(z, [tmp_apk.name], path_transform=path_transform) path_transform = lambda p: None if p == 'AndroidManifest.xml' else p build_utils.MergeZips(z, [options.in_apk], path_transform=path_transform)
def maybe_extract_version(j): try: return resource_utils.ExtractBinaryManifestValues( options.aapt2_path, j) except build_utils.CalledProcessError: return None