Esempio n. 1
0
def main(argv):
    argv = build_utils.expand_file_args(argv)
    args = parse_args(argv)
    # print(args)

    proguard = proguard_util.ProguardCmdBuilder(args.proguard_path)
    proguard.injars(build_utils.parse_gyp_list(args.input_paths))
    proguard.configs(build_utils.parse_gyp_list(args.proguard_configs))
    proguard.outjar(args.output_path)

    if args.mapping:
        proguard.mapping(args.mapping)

    if args.tested_apk_info:
        proguard.tested_apk_info(args.tested_apk_info)

    classpath = list(set(args.classpath))
    proguard.libraryjars(classpath)
    proguard.verbose(args.verbose)

    input_paths = proguard.get_inputs()

    proguard.check_output()
    if args.depfile:
        all_dep_paths = list(input_paths)
        all_dep_paths.extend(build_utils.get_python_dependencies())
        build_utils.write_dep_file(args.depfile, all_dep_paths)
        pass
    pass
Esempio n. 2
0
def main(argv):
    args = parse_args(argv)

    base_dir = args.base_dir
    build_utils.delete_directory(base_dir)
    build_utils.make_directory(base_dir)

    # generator_args = [
    #     "optional_field_style=reftypes",
    #     "store_unknown_fields=true"
    # ]
    out_arg = "--java_out=" + base_dir
    cmds = [
        args.protoc,
        "--proto_path", args.proto_path,
        out_arg
    ] + args.paths
    build_utils.check_output(cmds)

    if args.java_out_dir:
        build_utils.delete_directory(args.java_out_dir)
        shutil.copytree(base_dir, args.java_out_dir)
    else:
        build_utils.zip_dir(args.srcjar, base_dir)

    if args.depfile:
        all_dep_paths = build_utils.get_python_dependencies()
        build_utils.write_dep_file(args.depfile, all_dep_paths)
    pass
def main():
    args = parse_args()
    # print(args)

    package_command = _construct_most_aapt_args(args)

    output_paths = [args.aapt_path]

    if args.create_density_splits:
        for _, dst_path in _generate_density_split_paths(args.apk_path):
            output_paths.append(dst_path)
    output_paths.extend(
        _generate_language_split_output_paths(args.apk_path,
                                              args.language_splits))

    input_paths = [args.android_manifest] + args.resource_zips

    input_strings = []
    input_strings.extend(package_command)

    if args.asset_dir and os.path.exists(args.asset_dir):
        asset_paths = []
        for root, _, filenames in os.walk(args.asset_dir):
            asset_paths.extend(os.path.join(root, name) for name in filenames)
        input_paths.extend(asset_paths)
        input_strings.extend(sorted(asset_paths))
        pass

    _on_stale_md5(package_command, args)
    if args.depfile:
        build_utils.write_dep_file(args.depfile,
                                   build_utils.get_python_dependencies())
    pass
def main():
    parser = create_parser()
    args = parser.parse_args()

    build_utils.touch(args.output)

    if args.depfile:
        build_utils.write_dep_file(args.depfile,
                                   build_utils.get_python_dependencies())
    pass
Esempio n. 5
0
def main(argv):
    parser = create_parser()
    args = parser.parse_args(argv)

    inputs = build_utils.parse_gyp_list(args.inputs)
    output = args.output
    build_utils.do_zip(inputs, output, args.base_dir)

    if args.depfile:
        build_utils.write_dep_file(args.depfile,
                                   build_utils.get_python_dependencies())
    pass
Esempio n. 6
0
def main(argv):
    parser = create_parser()
    args = parse_args(parser, argv)

    paths = args.paths
    if ((args.proguard_enabled == 'true'
         and args.configuration_name == "Release")
            or (args.debug_build_proguard_enabled == 'true'
                and args.configuration_name == "Debug")):
        paths = [args.proguard_enabled_input_path]
        pass

    paths = list(paths)
    if args.inputs:
        paths += args.inputs

    if args.excluded_paths:
        excluded_paths = args.excluded_paths
        paths = [
            p for p in paths
            if os.path.relpath(p, args.output_directory) not in excluded_paths
        ]

    input_paths = list(paths)
    dx_name = "dx"
    if build_utils.is_windows():
        dx_name = "dx.bat"
    dx_binary = os.path.join(args.android_sdk_tools, dx_name)
    dex_cmd = [
        dx_binary, "--dex", "--num-threads=8", "--force-jumbo", "--output",
        args.dex_path
    ]

    if args.no_locals != "0":
        dex_cmd.append("--no-locals")

    if args.multi_dex:
        if args.main_dex_list_path:
            input_paths.append(args.main_dex_list_path)
        dex_cmd += [
            "--multi-dex",
        ]

    output_paths = [args.dex_path, args.dex_path + ".inputs"]

    _on_stale_md5(args, dex_cmd, paths)
    if args.depfile:
        all_dep_paths = list(input_paths)
        all_dep_paths.extend(build_utils.get_python_dependencies())
        build_utils.write_dep_file(args.depfile, all_dep_paths)
    pass
def main(argv):
    argv = build_utils.expand_file_args(argv)
    parser = argparse.ArgumentParser(prog="create_java_binary_script.py")
    build_utils.add_depfile_option(parser)
    parser.add_argument('--output', help='Output path for executable script.')
    parser.add_argument('--jar-path', help='Path to the main jar.')
    parser.add_argument(
        '--main-class',
        help='Name of the java class with the "main" entry point.')
    parser.add_argument('--classpath',
                        action='append',
                        default=[],
                        help='Classpath for running the jar.')
    parser.add_argument(
        '--bootclasspath',
        action='append',
        default=[],
        help='zip/jar files to add to bootclasspath for java cmd.')
    parser.add_argument("extra_program_args", nargs="*")
    args = parser.parse_args(argv)
    if args.extra_program_args is None:
        args.extra_program_args = []

    classpath = [args.jar_path]
    for cp_arg in args.classpath:
        classpath += build_utils.parse_gyp_list(cp_arg)

    bootclasspath = []
    for bootcp_arg in args.bootclasspath:
        bootclasspath += build_utils.parse_gyp_list(bootcp_arg)

    bootclasspath = [os.path.abspath(p) for p in bootclasspath]
    classpath = [os.path.abspath(p) for p in classpath]

    with open(args.output, 'w') as script:
        script.write(
            script_template.format(classpath=repr(classpath),
                                   bootclasspath=repr(bootclasspath),
                                   main_class=args.main_class,
                                   extra_program_args=repr(
                                       args.extra_program_args)))

    os.chmod(args.output, 0o750)

    if args.depfile:
        build_utils.write_dep_file(args.depfile,
                                   build_utils.get_python_dependencies())
def main(argv):
    argv = build_utils.expand_file_args(argv)
    parser = create_parser()
    args = parser.parse_args(argv)

    defines = []
    for arg in args.defines:
        defines.extend(build_utils.parse_gyp_list(arg))
    args.defines = defines

    do_gcc(args)

    if args.depfile:
        build_utils.write_dep_file(args.depfile,
                                   build_utils.get_python_dependencies())
    if args.stamp:
        build_utils.touch(args.stamp)
    pass
Esempio n. 9
0
def on_stale_md5(args):
    build_utils.remove_subtree(args.base_dir)
    build_utils.make_directory(args.base_dir)

    def predicate(name):
        if name.endswith(".class"):
            return False
        if name.startswith("META-INF/maven"):
            return False
        if name in ("META-INF/MANIFEST.MF", ):
            return False
        return True

    build_utils.extract_all(args.jar_path, args.base_dir, predicate=predicate)
    zip_files = build_utils.find_in_directory(args.base_dir, "*")
    build_utils.do_zip(zip_files, args.zipjar_path, args.base_dir)
    if args.depfile:
        dep_files = build_utils.get_python_dependencies()
        build_utils.write_dep_file(args.depfile, dep_files)
Esempio n. 10
0
def main():
    args = parse_args()
    # print(args)

    input_paths = [args.unsigned_apk_path, args.key_path]

    if args.load_library_from_zip:
        input_paths.append(args.rezip_apk_jar_path)

    input_strings = [
        args.load_library_from_zip, args.key_name, args.key_passwd,
        args.page_align_shared_libraries
    ]

    _finalize_apk(args)
    if args.depfile:
        python_deps = build_utils.get_python_dependencies()
        build_utils.write_dep_file(args.depfile, python_deps)

    pass
def main():
    parser = create_parser()
    args = parser.parse_args()

    build_utils.check_options(args, parser, required=['inputs'])
    inputs = build_utils.parse_gyp_list(args.inputs)

    if (args.output is None) == (args.outputs_zip is None):
        args.error('Exactly one of --output and --output-zip must be given')
    if args.output and len(inputs) != 1:
        args.error('--output cannot be used with multiple inputs')
    if args.outputs_zip and not args.inputs_base_dir:
        args.error('--inputs-base-dir must be given when --output-zip is used')

    variables = {}
    for v in build_utils.parse_gyp_list(args.variables):
        if '=' not in v:
            args.error('--variables argument must contain "=": ' + v)
        name, _, value = v.partition('=')
        variables[name] = value

    loader = RecordingFileSystemLoader(args.loader_base_dir)
    env = jinja2.Environment(loader=loader,
                             undefined=jinja2.StrictUndefined,
                             line_comment_prefix='##')
    if args.output:
        # 只处理单个文件
        process_file(env, inputs[0], args.loader_base_dir, args.output,
                     variables)
    else:
        # 处理多个文件
        process_files(env, inputs, args.loader_base_dir, args.inputs_base_dir,
                      args.outputs_zip, variables)

    if args.depfile:
        deps = loader.get_loaded_templates(
        ) + build_utils.get_python_dependencies()
        build_utils.write_dep_file(args.depfile, deps)
    pass
Esempio n. 12
0
def main(argv):
    args = parse_args(argv)

    base_dir = args.base_dir
    build_utils.delete_directory(base_dir)
    build_utils.make_directory(base_dir)

    for f in args.paths:
        classname = os.path.splitext(os.path.basename(f))[0]
        output = os.path.join(base_dir, classname + ".java")
        aidl_cmd = [args.aidl_path]
        for s in args.imports:
            aidl_cmd += ["-p", s]
        if args.includes:
            for s in args.includes:
                aidl_cmd += ["-I", s]
        aidl_cmd += [f, output]
        build_utils.check_output(aidl_cmd)
        pass

    with zipfile.ZipFile(args.srcjar, "w") as srcjar:
        for f in build_utils.find_in_directory(base_dir, "*.java"):
            with open(f, "r") as fileobj:
                data = fileobj.read()
                pass

            pkg_name = re.compile(r"^\s*package\s+(.*?)\s*;",
                                  re.M).search(data).group(1)
            arcname = "%s/%s" % (pkg_name.replace(".",
                                                  "/"), os.path.basename(f))
            srcjar.writestr(arcname, data)
        pass

    if args.depfile:
        all_dep_paths = build_utils.get_python_dependencies()
        build_utils.write_dep_file(args.depfile, all_dep_paths)
    pass
Esempio n. 13
0
def main(argv):
    argv = build_utils.expand_file_args(argv)
    args = parse_options(argv)
    # print(args)

    java_files = list(args.java_files)
    if args.src_gendirs:
        java_files.extend(
            build_utils.find_in_directories(args.src_gendirs, "*.java"))

    java_files = _filter_java_files(java_files, args.javac_includes)

    javac_cmd = ["javac"]
    javac_cmd.extend([
        "-g",
        "-encoding",
        "utf-8",
        "-classpath",
        build_utils.CLASSPATH_SEP.join(args.classpath),
        "-sourcepath",
        "",
        "-source",
        "1.8",
        "-target",
        "1.8",
    ])

    if args.bootclasspath:
        javac_cmd.extend([
            "-bootclasspath",
            build_utils.CLASSPATH_SEP.join(args.bootclasspath)
        ])

    _on_stale_md5(args, javac_cmd, java_files)
    all_inputs = build_utils.get_python_dependencies()
    build_utils.write_dep_file(args.depfile, all_inputs)
    pass
def main(argv):
    argv = build_utils.expand_file_args(argv)
    parser = create_parser()
    args = parser.parse_args(argv)
    # print(args)

    if args.multidex_configuration_path:
        multidex_config = build_utils.read_json(
            args.multidex_configuration_path)
        if not multidex_config.get("enabled", False):
            return 0

    if args.inputs:
        args.paths.extend(build_utils.parse_gyp_list(args.inputs))

    shrinked_android_jar = os.path.abspath(
        os.path.join(args.android_sdk_tools, 'lib', 'shrinkedAndroid.jar'))
    dx_jar = os.path.abspath(
        os.path.join(args.android_sdk_tools, 'lib', 'dx.jar'))
    rules_file = os.path.abspath(
        os.path.join(args.android_sdk_tools, 'mainDexClasses.rules'))

    proguard_cmd = [
        "java",
        "-jar",
        args.proguard_jar_path,
        '-forceprocessing',
        '-dontwarn',
        '-dontoptimize',
        '-dontobfuscate',
        '-dontpreverify',
        '-libraryjars',
        shrinked_android_jar,
        '-include',
        rules_file,
    ]
    for m in args.main_dex_rules_paths:
        proguard_cmd.extend(["-include", m])
        pass

    main_dex_list_cmd = [
        "java",
        "-cp",
        dx_jar,
        "com.android.multidex.MainDexListBuilder",
    ]

    input_paths = list(args.paths)
    input_paths += [
        shrinked_android_jar,
        dx_jar,
        rules_file,
    ]
    input_paths += args.main_dex_rules_paths

    input_strings = [
        proguard_cmd,
        main_dex_list_cmd,
    ]

    output_paths = [
        args.main_dex_list_path,
    ]

    _on_stale_md5(args, proguard_cmd, main_dex_list_cmd, args.paths,
                  args.main_dex_list_path)
    if args.depfile:
        all_dep_paths = list(input_paths)
        all_dep_paths.extend(build_utils.get_python_dependencies())
        build_utils.write_dep_file(args.depfile, all_dep_paths)
    pass
Esempio n. 15
0
def main():
    parser = create_parser()
    args = parser.parse_args()

    requires_options_map = {
        "java_library": ["build_config", "jar_path", "srczip_path"],
        "java_binary": ["build_config", "jar_path"],
        "android_resources": ["build_config", "resources_zip"],
        "android_assets": ["build_config"],
        "android_native_libraries": ["build_config", "native_libs"],
        "android_apk": ["build_config", "apk_path", "dex_path"],
        "deps_dex": ["build_config", "dex_path"],
        "group": ["build_config"]
    }

    # 检查必须的选项
    requires_options = requires_options_map.get(args.type)
    if requires_options is None:
        raise Exception("Unknown type: %s" % args.type)

    build_utils.check_options(args, parser, required=requires_options)

    if type == "java_library":
        if args.supports_android and not args.dex_path:
            raise Exception(
                "--dex-path must be set if --supports-android is enabled")
        if args.requires_android and not args.supports_android:
            raise Exception(
                "--supports-android must be set is --requires-android is enabled")
        pass

    if args.possible_deps_configs is None:
        args.possible_deps_configs = []

    possible_deps_config_paths = args.possible_deps_configs

    allow_unknown_deps = (args.type in (
        "android_apk", "android_resources", "android_assets", "android_native_libraries"))
    unknown_deps = [
        c for c in possible_deps_config_paths if not os.path.exists(c)]
    if not allow_unknown_deps and unknown_deps:
        raise Exception("Unknown deps: %s" % str(unknown_deps))

    # 直接依赖
    direct_deps_config_paths = [c for c in possible_deps_config_paths
                                if c not in unknown_deps]
    direct_deps_config_paths = _filter_unwanted_deps_configs(args.type,
                                                             direct_deps_config_paths)
    deps = Deps(direct_deps_config_paths)
    all_inputs = deps.all_config_paths() + build_utils.get_python_dependencies()

    if args.has_alternative_locale_resource:
        # 移除其他的资源
        alternative = [c["path"] for c in deps.direct("android_resources")
                       if c["is_locale_resource"]]
        if len(alternative) != 1:
            raise Exception()
        unwanted = [c["path"] for c in deps.all("android_resources")
                    if c["is_locale_resource"]]
        for path in unwanted:
            if path != alternative[0]:
                deps.remove_non_direct_dep(unwanted)
        pass

    config = {
        "deps_info": {
            "name": os.path.basename(args.build_config),
            "path": args.build_config,
            "type": args.type,
            "deps_configs": direct_deps_config_paths
        }
    }
    deps_info = config["deps_info"]

    direct_library_deps = deps.direct("java_library")
    all_library_deps = deps.all("java_library")
    direct_resources_deps = deps.direct("android_resources")
    all_resources_deps = deps.all("android_resources")
    all_resources_deps.reverse()
    all_native_libraries_deps = deps.all("android_native_libraries")

    if args.type == "android_apk" and args.tested_apk_config:
        tested_apk_deps = Deps([args.tested_apk_config])
        tested_apk_resource_deps = tested_apk_deps.all("android_resources")
        direct_resources_deps = [d for d in direct_resources_deps
                                 if d not in tested_apk_resource_deps]
        all_resources_deps = [d for d in all_resources_deps
                              if d not in tested_apk_resource_deps]
        pass

    if args.type in ("java_library", "java_binary") and not args.bypass_platform_checks:
        deps_info["requires_android"] = args.requires_android
        deps_info["supports_android"] = args.supports_android

        deps_requires_android = [d["name"] for d in all_library_deps
                                 if d["requires_android"]]
        deps_not_supports_android = [d["name"] for d in all_library_deps
                                     if not d["supports_android"]]
        if not args.requires_android and deps_requires_android:
            raise Exception("Some deps requires building for the android platform: %s"
                            % " ".join(deps_requires_android))
        if args.supports_android and deps_not_supports_android:
            raise Exception("Some deps not supports running on the android platform: %s"
                            % " ".join(deps_not_supports_android))
        pass

    if args.type in ("java_library", "java_binary", "android_apk"):
        javac_classpath = [c["jar_path"] for c in direct_library_deps]
        java_full_classpath = [c["jar_path"] for c in all_library_deps]
        config["resources_deps"] = [c["path"] for c in all_resources_deps]
        deps_info["jar_path"] = args.jar_path
        deps_info["srczip_path"] = args.srczip_path
        if args.type == "android_apk" or args.supports_android:
            deps_info["dex_path"] = args.dex_path
        if args.type == "android_apk":
            deps_info["apk_path"] = args.apk_path
            deps_info["incremental_apk_path"] = args.incremental_apk_path
            deps_info["incremental_install_script_path"] = args.incremental_install_script_path

        config["javac"] = {}
        pass

    if args.type in ("java_binary", "java_library"):
        config["javac"]["srcjars"] = [c["srcjar"]
                                      for c in direct_resources_deps]
    if args.type == "android_apk":
        config["javac"]["srcjars"] = []

    if args.type == "android_assets":
        all_assets_sources = []
        if args.asset_renaming_sources:
            all_assets_sources.extend(args.asset_renaming_sources)
        if args.asset_sources:
            all_assets_sources.extend(args.asset_sources)
        deps_info["assets"] = {
            "sources": all_assets_sources,
        }

        all_assets_outputs = []
        if args.asset_renaming_destinations:
            all_assets_outputs.extend(args.asset_renaming_destinations)
        deps_info["assets"]["outputs"] = all_assets_outputs
        deps_info["assets"]["disable_compression"] = args.disable_asset_compression
        pass

    if args.type == "android_resources":
        deps_info["resources_zip"] = args.resources_zip
        deps_info["r_text"] = args.r_text
        deps_info["is_locale_resource"] = args.is_locale_resource
        if args.srcjar:
            deps_info["srcjar"] = args.srcjar
        if args.android_manifest:
            manifest = AndroidManifest(args.android_manifest)
            deps_info["package_name"] = manifest.get_package_name()
        if args.package_name:
            deps_info["package_name"] = args.package_name
        pass

    if args.type == "android_native_libraries":
        deps_info["native_libs"] = build_utils.parse_gyp_list(args.native_libs)
        pass

    if args.type in ("android_resources", "android_apk", "resources_rewriter"):
        config["resources"] = {}
        config["resources"]["dependency_zips"] = [d["resources_zip"]
                                                  for d in all_resources_deps]
        config["resources"]["extra_package_names"] = []
        config["resources"]["extra_r_text_files"] = []
        pass

    if args.type in ("android_apk", "android_resources", "resources_rewriter"):
        config["resources"]["extra_package_names"] = [c["package_name"] for c in all_resources_deps
                                                      if "package_name" in c]
        config["resources"]["extra_r_text_files"] = [c["r_text"] for c in all_resources_deps
                                                     if "r_text" in c]

    if args.type in ("android_apk", "deps_dex"):
        deps_dex_paths = [c["dex_path"] for c in all_library_deps]

    proguard_enabled = args.proguard_enabled
    if args.type == "android_apk":
        deps_info["proguard_enabled"] = proguard_enabled

    if proguard_enabled:
        deps_info["proguard_info"] = args.proguard_info
        config["proguard"] = {}
        proguard_config = config["proguard"]
        proguard_config["input_paths"] = [args.jar_path] + java_full_classpath

    if args.type in ("android_apk", "deps_dex"):
        config["final_dex"] = {}
        dex_config = config["final_dex"]
        dex_config["dependency_dex_files"] = deps_dex_paths
        pass

    if args.type in ("android_apk", "java_library", "java_binary"):
        config["javac"]["classpath"] = javac_classpath
        config["javac"]["interface_classpath"] = [as_interface_jar(path)
                                                  for path in javac_classpath]
        config["java"] = {
            "full_classpath": java_full_classpath
        }

    if args.type == "android_apk":
        dependency_jars = [c["jar_path"] for c in all_library_deps]
        all_interface_jars = [as_interface_jar(p)
                              for p in dependency_jars + [args.jar_path]]
        all_srczips = [c["srczip_path"] for c in all_library_deps]
        all_srczips.append(args.srczip_path)
        config["dist_jar"] = {
            "dependency_jars": dependency_jars,
            "all_interface_jars": all_interface_jars,
            "all_srczips": all_srczips,
        }

        manifest = AndroidManifest(args.android_manifest)
        deps_info["package_name"] = manifest.get_package_name()

        if not args.tested_apk_config and manifest.get_instrumentation():
            manifest.check_instrumentation(manifest.get_package_name())

        library_paths = []
        java_libraries_list_holder = [None]
        libraries = build_utils.parse_gyp_list(args.native_libs or '[]')
        for d in all_native_libraries_deps:
            libraries.extend(d["native_libs"])

        if libraries:
            all_deps = [path for path in libraries]
            library_paths = [path for path in all_deps]
            java_libraries_list_holder[0] = ("{%s}" % ",".join(
                ['"%s"' % s[3:-3] for s in library_paths]))
            pass

        all_inputs.extend(library_paths)
        config["native"] = {
            "libraries": library_paths,
            "java_libraries_list": java_libraries_list_holder[0]
        }

        config["assets"], config["uncompressed_assets"] = _merge_assets(
            deps.all("android_assets"))
        pass

    build_utils.write_json(config, args.build_config)
    if args.depfile:
        build_utils.write_dep_file(args.depfile, all_inputs)
    pass
Esempio n. 16
0
def main(argv):
    args = parse_args(argv)
    # print(args)

    native_libs = sorted(args.native_libs)
    input_paths = [args.resource_apk, __file__] + native_libs

    secondary_native_libs = []
    if args.secondary_native_libs:
        secondary_native_libs = sorted(args.secondary_native_libs)
        input_paths += secondary_native_libs

    if args.dex_file:
        input_paths.append(args.dex_file)

    if args.emma_device_jar:
        input_paths.append(args.emma_device_jar)

    input_strings = [
        args.android_abi, args.native_lib_placeholders,
        args.uncompress_shared_libraries
    ]

    if args.secondary_android_abi:
        input_strings.append(args.secondary_android_abi)

    _assets = _expand_paths(args.assets)
    _uncompressed_assets = _expand_paths(args.uncompressed_assets)

    for src_path, dest_path in itertools.chain(_assets, _uncompressed_assets):
        input_paths.append(src_path)
        input_strings.append(dest_path)
        pass

    def on_stale_md5(args):
        tmp_apk = args.output_apk + ".tmp"
        try:
            with zipfile.ZipFile(args.resource_apk) as resource_apk, \
                    zipfile.ZipFile(tmp_apk, "w", zipfile.ZIP_DEFLATED) as out_apk:

                def copy_resource(zipinfo):
                    compress = zipinfo.compress_type != zipfile.ZIP_STORED
                    build_utils.add_to_zip_hermetic(out_apk,
                                                    zipinfo.filename,
                                                    data=resource_apk.read(
                                                        zipinfo.filename),
                                                    compress=compress)

                resource_infos = resource_apk.infolist()

                assert (resource_infos[0].filename == "AndroidManifest.xml")
                # 1.AndroidManifest.xml
                copy_resource(resource_infos[0])

                # 2.Assets
                if args.write_asset_list:
                    data = _create_assets_list(
                        itertools.chain(_assets, _uncompressed_assets))
                    build_utils.add_to_zip_hermetic(out_apk,
                                                    "assets/assets_list",
                                                    data=data)
                _add_assets(out_apk, _assets, disable_compression=False)
                _add_assets(out_apk,
                            _uncompressed_assets,
                            disable_compression=True)

                # 3. Dex files.
                if args.dex_file and args.dex_file.endswith(".zip"):
                    with zipfile.ZipFile(args.dex_file, mode="r") as dex_zip:
                        for dex in (d for d in dex_zip.namelist()
                                    if d.endswith(".dex")):
                            build_utils.add_to_zip_hermetic(
                                out_apk, dex, data=dex_zip.read(dex))
                elif args.dex_file:
                    build_utils.add_to_zip_hermetic(out_apk,
                                                    "classes.dex",
                                                    src_path=args.dex_file)

                # 4.Native libraries
                _add_native_libraries(out_apk, native_libs, args.android_abi,
                                      args.uncompress_shared_libraries)
                if args.secondary_native_libs:
                    _add_native_libraries(out_apk, args.secondary_native_libs,
                                          args.secondary_android_abi,
                                          args.uncompress_shared_libraries)

                for name in sorted(args.native_lib_placeholders):
                    apk_path = "lib/%s/%s" % (args.android_abi, name)
                    build_utils.add_to_zip_hermetic(out_apk, apk_path, data='')

                # 5. Resources
                for info in resource_infos[1:]:
                    copy_resource(info)

                # 6. Java resources. Used only when coverage is enabled, so order
                # doesn't matter
                if args.emma_device_jar:
                    with zipfile.ZipFile(args.emma_device_jar,
                                         "r") as emma_device_jar:
                        for apk_path in emma_device_jar.namelist():
                            apk_path_lower = apk_path.lower()
                            if apk_path_lower.startswith("meta-inf/"):
                                continue
                            if apk_path_lower.endswith("/"):
                                continue

                            if apk_path_lower.endswith(".class"):
                                continue

                            build_utils.add_to_zip_hermetic(
                                out_apk,
                                apk_path,
                                data=emma_device_jar.read(apk_path))

                # 7. srczip files.
                if args.srczip_path:
                    with zipfile.ZipFile(args.srczip_path, "r") as srczip_file:
                        for apk_path in srczip_file.namelist():
                            apk_path_lower = apk_path.lower()
                            if apk_path_lower.startswith(
                                    "meta-inf/manifest.mf"):
                                continue
                            if apk_path_lower.endswith("/"):
                                continue
                            if apk_path_lower.endswith(".class"):
                                continue

                            build_utils.add_to_zip_hermetic(
                                out_apk,
                                apk_path,
                                data=srczip_file.read(apk_path))
                pass

            shutil.move(tmp_apk, args.output_apk)
            pass
        finally:
            if os.path.exists(tmp_apk):
                os.remove(tmp_apk)
        pass

    on_stale_md5(args)
    if args.depfile:
        python_deps = build_utils.get_python_dependencies()
        build_utils.write_dep_file(args.depfile, python_deps)
    pass