packages feed

cabal-buck2-0.6.0.0: buck2/prelude/decls/android_rules.bzl

# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is dual-licensed under either the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree or the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree. You may select, at your option, one of the
# above-listed licenses.

# TODO(cjhopman): This was generated by scripts/hacks/rules_shim_with_docs.py,
# but should be manually edited going forward. There may be some errors in
# the generated docs, and so those should be verified to be accurate and
# well-formatted (and then delete this TODO)

load("@prelude//:attrs_validators.bzl", "validation_common")
load("@prelude//:genrule.bzl", "genrule_attributes")
load(
    "@prelude//:validation_deps.bzl",
    "VALIDATION_DEPS_ATTR_NAME",
)
load("@prelude//android:build_only_native_code.bzl", "is_build_only_native_code")
load("@prelude//android:configuration.bzl", "CPU_TRANSITION_ATTRS", "cpu_split_transition", "cpu_transition", "is_building_android_binary_attr")
load("@prelude//android:cpu_filters.bzl", "ALL_CPU_FILTERS")
load("@prelude//decls:test_common.bzl", "test_common")
load("@prelude//transitions:constraint_overrides.bzl", "constraint_overrides")
load("@prelude//utils:clear_platform.bzl", "clear_platform_transition")
load(":android_common.bzl", "android_common")
load(":common.bzl", "TestType", "buck", "prelude_rule")
load(":core_rules.bzl", "TargetCpuType")
load(":genrule_common.bzl", "genrule_common")
load(":java_rules.bzl", "dex_min_sdk_version")
load(":jvm_common.bzl", "jvm_common")
load(":re_test_common.bzl", "re_test_common")
load(":toolchains_common.bzl", "toolchains_common")

DexStore = ["raw", "raw_subdir", "jar", "xzs"]

DuplicateResourceBehaviour = ["allow_by_default", "ban_by_default"]

ExopackageMode = ["secondary_dex", "native_library", "resources", "modules", "arch64"]

JvmLanguage = ["java", "kotlin", "scala"]

PackageType = ["debug", "instrumented", "release", "test"]

RType = [
    "anim",
    "animator",
    "array",
    "attr",
    "bool",
    "color",
    "dimen",
    "drawable",
    "fraction",
    "font",
    "id",
    "integer",
    "interpolator",
    "layout",
    "menu",
    "navigation",
    "mipmap",
    "plurals",
    "raw",
    "string",
    "style",
    "styleable",
    "transition",
    "xml",
]

ResourceCompressionMode = ["disabled", "enabled", "enabled_strings_only", "enabled_with_strings_as_assets"]

SdkProguardType = ["default", "optimized", "none"]

# @oss-disable[end= ]: GatoradePhase = ["early", "middle", "late"]

DISABLE_STRIPPING = read_root_config("android", "disable_stripping") in ("True", "true")

# Format is {"ovveride_name": {"re_cap_key": "re_cap_value"}}; for example:
#    {
#        "dynamic-listing": {
#            "platform": "riot",
#            "pool": "EUREKA_POOL",
#        },
#        "test-execution": {
#            "platform": "riot",
#            "pool": "EUREKA_POOL",
#        },
#    }
RE_CAPS = attrs.option(attrs.dict(key = attrs.string(), value = attrs.dict(key = attrs.string(), value = attrs.string())), default = None)

# Format is {"ovveride_name": "re_use_case"}; for example:
#     {
#         "dynamic-listing": "riot",
#         "test-execution": "riot",
#     }
RE_USE_CASE = attrs.option(attrs.dict(key = attrs.string(), value = attrs.string()), default = None)

# Format is {"ovveride_name": {"param_name": param_value}}; for example:
#    {
#        "remote_execution_policy": {"setup_preference_key": "some_json_string"},
#    }
META_INTERNAL_EXTRA_PARAMS = attrs.option(attrs.dict(key = attrs.string(), value = attrs.any()), default = None)

# Common attributes shared between android_binary and android_bundle rules
ANDROID_BINARY_BUNDLE_COMMON_ATTRS = (
    {
        "aapt2_keep_raw_values": attrs.bool(default = False, doc = ""),
        "aapt2_locale_filtering": attrs.bool(default = False, doc = ""),
        "aapt2_preferred_density": attrs.option(attrs.string(), default = None, doc = ""),
        "additional_aapt_params": attrs.list(attrs.string(), default = [], doc = ""),
        "allow_r_dot_java_in_secondary_dex": attrs.bool(default = False, doc = ""),
        "allowed_duplicate_resource_types": attrs.list(
            attrs.enum(RType),
            default = [],
            doc = "Similar to banned_duplicate_resource_types, but lists the types that are allowed to have duplicates. This should only be used if duplicate_resource_behavior is 'ban_by_default'.",
        ),
        "android_sdk_proguard_config": attrs.option(
            attrs.enum(SdkProguardType),
            default = None,
            doc = "The type of proguard configuration to use from the Android SDK. Options are 'default' to use the default config, 'optimized' to use the config with optimizations enabled, or 'none' to not use any standard configuration (you will need to supply your own version, otherwise your app will probably not work).",
        ),
        "application_module_blocklist": attrs.option(attrs.list(attrs.transition_dep(cfg = cpu_transition)), default = None, doc = ""),
        "application_module_configs": attrs.dict(
            key = attrs.string(),
            value = attrs.list(attrs.transition_dep(cfg = cpu_transition)),
            sorted = False,
            default = {},
            doc = "A map of module names to lists of targets, where the targets should seed the corresponding module. The seed targets and their exclusive dependencies are packaged into the APK in separate files to allow them to be loaded independently.",
        ),
        "application_module_dependencies": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.string()), sorted = False), default = None, doc = ""),
        "banned_duplicate_resource_types": attrs.list(
            attrs.enum(RType),
            default = [],
            doc = "If ['string'] is used, the build will break if multiple string resources with the same name are added in an app's Android Resources. Resource names are name-spaced by resource type, this does not enforce unique names between multiple resource types. AAPT does not enforce this, but you can prevent easy-to-introduce resource bugs by enabling this.",
        ),
        "build_config_values": attrs.list(attrs.string(), default = [], doc = "See the documentation on the values argument for android_build_config()."),
        "build_config_values_file": attrs.option(
            attrs.one_of(attrs.transition_dep(cfg = cpu_transition), attrs.source()),
            default = None,
            doc = "See the documentation on the values_file argument for android_build_config().",
        ),
        "build_string_source_map": attrs.bool(default = False, doc = ""),
        "compiled_resource_apks": attrs.list(attrs.source(), default = [], doc = ""),
        "cpu_filters": attrs.list(
            attrs.enum(TargetCpuType),
            default = [],
            doc = """The CPU architecture filter applied to the final apk. Could be a subset of ARM, ARMV7, ARM64, X86, X86_64, MIPS. \
Note: If you set this parameter, you must setup your NDK, otherwise Buck build will fail.""",
        ),
        "default_module_manifest_skeleton": attrs.option(attrs.one_of(attrs.transition_dep(cfg = cpu_transition), attrs.source()), default = None, doc = ""),
        "defer_relink": attrs.bool(default = False),
        "deps": attrs.list(
            attrs.split_transition_dep(cfg = cpu_split_transition),
            default = [],
            doc = """List of build targets whose corresponding compiled Java code, Android resources, and native libraries will be included in the APK. \
From the transitive closure of these dependencies, the outputs of rules of the following type will be included in the APK: \
android_library(), android_resource(), cxx_library(), groovy_library(), java_library(), java_binary(), prebuilt_jar(), prebuilt_native_library().""",
        ),
        "dex_compression": attrs.option(attrs.enum(DexStore), default = None, doc = ""),
        "disable_pre_dex": attrs.bool(default = False, doc = ""),
        "duplicate_class_checker_enabled": attrs.bool(default = False, doc = ""),
        "duplicate_resource_behavior": attrs.enum(
            DuplicateResourceBehaviour,
            default = "allow_by_default",
            doc = "If set to 'ban_by_default', duplicate resource definitions with the same type and name will cause the build to fail, unless they are excluded by allowed_duplicate_resource_types or duplicate_resource_whitelist. If set to 'allow_by_default' (the default), no duplicate resource checks will be performed. They can still be enabled on individual types by using banned_duplicate_resource_types.",
        ),
        "duplicate_resource_whitelist": attrs.option(
            attrs.source(),
            default = None,
            doc = "Either a build target or a path to a file containing a whitelist of resources that should be excluded from duplicate resource detection. Format is one resource per line with the type followed by the name, separated by a space. For example, 'string app_name'.",
        ),
        "enable_bootstrap_dexes": attrs.bool(default = False, doc = ""),
        "enable_relinker": attrs.bool(default = False, doc = ""),
        "exclude_duplicate_targets_do_not_use": attrs.list(attrs.dep(), default = [], doc = ""),
        "exopackage_modes": attrs.list(attrs.enum(ExopackageMode), default = [], doc = ""),
        "extra_filtered_resources": attrs.list(attrs.string(), default = [], doc = ""),
        "extra_no_compress_asset_extensions": attrs.list(attrs.string(), default = [], doc = ""),
        "extra_no_compress_asset_regex": attrs.option(attrs.string(), default = None, doc = ""),
        "extra_relinker_outputs": attrs.list(attrs.string(), default = [], doc = ""),
        # @oss-disable[end= ]: "gatorade_extra_args": attrs.list(attrs.arg(), default = [], doc = "Extra Gatorade cross-library step arguments"),
        # @oss-disable[end= ]: "gatorade_phases": attrs.set(attrs.enum(GatoradePhase), default = []),
        "ignore_aapt_proguard_config": attrs.bool(default = False, doc = "If true, the proguard config automatically generated by aapt will be ignored."),
        "include_build_info_file": attrs.bool(
            # @oss-disable[end= ]: default = True,
            default = False, # @oss-enable
            doc = "Bake `assets/BuildInfo.json` with the buck2 `BUCK_BUILD_ID` into the APK so an installed build can be resolved back to its buck2 build and source commit. On by default for non-release builds in fbsource; set this attribute to `False` to disable. The `apk_build` action invokes a toolchain-provided generator to write the file, so the baked id refreshes when the APK content changes and a no-op rebuild reuses a prior (equally valid) id.",
        ),
        "includes_vector_drawables": attrs.bool(
            default = False,
            doc = "When calling AAPT during the packaging process, pass the --no-version-vectors flag which ensures that any vector drawables which make use of the Android support library are backwards compatible with Android 4.4 and earlier.",
        ),
        "is_cacheable": attrs.bool(default = False, doc = ""),
        "is_voltron_language_pack_enabled": attrs.bool(default = False, doc = ""),
        "keystore": attrs.dep(doc = "A build target that identifies a keystore to use to sign the APK."),
        "locales": attrs.list(attrs.string(), default = [], doc = ""),
        "manifest": attrs.option(
            attrs.one_of(attrs.transition_dep(cfg = cpu_transition), attrs.source()),
            default = None,
            doc = """Relative path to the Android manifest for the APK. The common case is that the manifest will be in the same directory as the rule, in which case this will simply be 'AndroidManifest.xml', but it can also reference an `android_manifest()` rule. Prefer using `manifest_skeleton`, which performs merging automatically. Exactly one of `manifest` and `manifest_skeleton` must be set.""",
        ),
        "manifest_entries": attrs.dict(
            key = attrs.string(),
            value = attrs.any(),
            default = {},
            doc = "Insert values into the packaged AndroidManifest.xml file. Valid values are min_sdk_version, target_sdk_version, version_code, version_name, and debug_mode.",
        ),
        "manifest_skeleton": attrs.option(
            attrs.one_of(attrs.transition_dep(cfg = cpu_transition), attrs.source()),
            default = None,
            doc = """Relative path to the skeleton Android manifest for the APK. An `android_manifest()` will be created automatically to merge all manifests from libraries and resources going into the app. The common case is that the manifest will be in the same directory as the rule, in which case this will simply be 'AndroidManifest.xml'. Exactly one of `manifest` and `manifest_skeleton` must be set.""",
        ),
        "min_sdk_version": attrs.option(attrs.int(), default = None),
        "minimize_primary_dex_size": attrs.bool(default = False, doc = ""),
        "multidex_min_api": attrs.option(attrs.string(), default = None, doc = ""),
        "native_library_bolt_args": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.arg())), default = None, doc = ""),
        "native_library_merge_code_generator": attrs.option(attrs.exec_dep(), default = None, doc = ""),
        "native_library_merge_glue": attrs.option(attrs.split_transition_dep(cfg = cpu_split_transition), default = None, doc = ""),
        "native_library_merge_linker_args": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.arg())), default = None, doc = ""),
        "native_library_merge_linker_args_all": attrs.list(attrs.arg(), default = [], doc = "Extra linker arguments passed to all merged libraries."),
        "native_library_merge_map": attrs.option(
            attrs.dict(key = attrs.string(), value = attrs.list(attrs.regex()), sorted = False),
            default = None,
            doc = "An advanced option for apps with many native libraries.",
        ),
        "native_library_merge_non_asset_libs": attrs.bool(default = False, doc = ""),
        "native_library_merge_sequence": attrs.option(
            attrs.list(
                attrs.one_of(
                    attrs.tuple(attrs.string(), attrs.list(attrs.regex())),
                    attrs.list(attrs.tuple(attrs.string(), attrs.list(attrs.regex()))),
                ),
            ),
            default = None,
            doc = """Defines a prioritized sequence of instructions for merging native libraries. Sequence entries are tuples comprised of a merged library name and a list of regular expressions for which matching native library targets and their dependencies will be added to the merged library, unless an earlier entry already matched them. Merged library names must begin with `lib` and end with `.so`. This is an advanced option for apps with many native libraries.""",
        ),
        "native_library_merge_sequence_blocklist": attrs.option(
            attrs.list(attrs.regex()),
            default = None,
            doc = """Defines a list of regular expressions for which matching native library targets will not be merged by `native_library_merge_sequence`. Blocked targets' unblocked dependencies will still be merged.""",
        ),
        "native_library_pick_first": attrs.list(attrs.string(), default = [], doc = ""),
        "no_dx": attrs.list(
            attrs.dep(),
            default = [],
            doc = """List of dependency targets whose Java code should be excluded from the DEX files in the final APK. \
The classes from these targets will not be dexed, but their other resources will still be included. \
This might be useful to resolve duplicate class errors when multiple dependencies provide the same class. \
See [this document](https://www.internalfb.com/intern/staticdocs/confucius/docs/notes/dev/projects/android/resolving_duplicate_classes_with_no_dx/) \
for how to resolve duplicate classes using this attribute.""",
        ),
        "optimization_passes": attrs.int(default = 1, doc = ""),
        "package_asset_libraries": attrs.bool(default = False, doc = ""),
        "package_type": attrs.enum(
            PackageType,
            default = "debug",
            doc = "Determines whether ProGuard will be used when packaging the APK. Acceptable values for package_type are 'debug' and 'release'. The default value is 'debug', which indicates that ProGuard should not be used.",
        ),
        "package_validators": attrs.list(
            attrs.tuple(
                attrs.exec_dep(providers = [RunInfo]),
                attrs.list(attrs.arg(), default = []),
            ),
            default = [],
        ),
        "package_voltron_asset_libraries": attrs.bool(
            default = False,
            doc = "Similar global flag as package_asset_libraries to control voltron module libs specifically.",
        ),
        "packaged_locales": attrs.list(attrs.string(), default = [], doc = ""),
        "packaging_options": attrs.dict(key = attrs.string(), value = attrs.list(attrs.string()), default = {}, doc = ""),
        "post_filter_resources_cmd": attrs.option(attrs.arg(), default = None, doc = ""),
        "preinline_ir_sonames": attrs.list(attrs.string(), default = [], doc = "Sonames the pre-inline IR dump is restricted to (empty = all)."),
        "preprocess_java_classes_bash": attrs.option(attrs.arg(), default = None, doc = ""),
        "preprocess_java_classes_deps": attrs.list(attrs.dep(), default = [], doc = ""),
        "primary_dex_patterns": attrs.list(attrs.string(), default = [], doc = ""),
        "proguard_config": attrs.option(
            attrs.source(),
            default = None,
            doc = "Relative path to a ProGuard configuration file that will be passed via the -include flag when package_type is 'release'.",
        ),
        "proguard_jvm_args": attrs.list(attrs.string(), default = [], doc = ""),
        "relinker_extra_args": attrs.dict(
            key = attrs.string(),
            value = attrs.list(attrs.arg()),
            sorted = False,
            default = {},
            doc = "Per-library extra linker arguments passed when relinking, mapping sonames to lists of arguments.",
        ),
        "relinker_extra_args_all": attrs.list(attrs.arg(), default = [], doc = "Extra arguments passed when relinking all libraries."),
        "relinker_extra_deps": attrs.list(
            attrs.split_transition_dep(cfg = cpu_split_transition),
            default = [],
            doc = "Deps statically linked to every native lib by the relinker.",
        ),
        "relinker_whitelist": attrs.list(attrs.regex(), default = [], doc = ""),
        "resource_compression": attrs.enum(ResourceCompressionMode, default = "disabled", doc = ""),
        "resource_filter": attrs.list(attrs.string(), default = [], doc = ""),
        "resource_stable_ids": attrs.option(attrs.source(), default = None, doc = ""),
        "secondary_dex_weight_limit": attrs.option(attrs.int(), default = None, doc = ""),
        "shared_libraries_to_exclude": attrs.list(attrs.label(), default = [], doc = ""),
        "skip_crunch_pngs": attrs.option(attrs.bool(), default = None, doc = "If True, PNGs in the APK are not crushed by aapt."),
        "skip_proguard": attrs.bool(
            default = False,
            doc = "To produce a release build without running ProGuard set the skip_proguard flag to True. This will still cause ProGuard configuration files to be generated for use by other optimizers like Redex.",
        ),
        "trim_resource_ids": attrs.bool(default = False, doc = ""),
        "use_split_dex": attrs.bool(
            default = False,
            doc = """If this argument is True, Buck enables multidex support for the output APK. \
Multidex support enables your app to use multiple Dalvik Executable (DEX) bytecode files and thereby \
work around the 64K limit on the number of methods that can be referenced in a single DEX file.""",
        ),
        "xz_compression_level": attrs.int(default = 4, doc = ""),
        "_android_toolchain": toolchains_common.android(),
        "_cxx_toolchain": attrs.split_transition_dep(cfg = cpu_split_transition, default = "toolchains//:android-hack"),
        "_dex_toolchain": toolchains_common.dex(),
        "_exec_os_type": buck.exec_os_type_arg(),
        "_is_building_android_binary": attrs.default_only(attrs.bool(default = True)),
        "_java_toolchain": toolchains_common.java_for_android(),
        VALIDATION_DEPS_ATTR_NAME: attrs.set(attrs.transition_dep(cfg = cpu_transition), sorted = True, default = []),
    }
    | CPU_TRANSITION_ATTRS
    | buck.licenses_arg()
    | buck.labels_arg()
    | buck.contacts_arg()
)

ANDROID_BINARY_ATTRS = (
    ANDROID_BINARY_BUNDLE_COMMON_ATTRS
    | {
        "strip_libraries": attrs.bool(default = not DISABLE_STRIPPING),
    }
    | constraint_overrides.attributes
)
ANDROID_BUNDLE_ATTRS = ANDROID_BINARY_BUNDLE_COMMON_ATTRS | {
    "bundle_config_file": attrs.option(attrs.source(), default = None, doc = ""),
    "module_manifest_skeleton": attrs.dict(
        default = {},
        key = attrs.string(),
        sorted = False,
        value = attrs.one_of(attrs.transition_dep(cfg = cpu_transition), attrs.source()),
        doc = "",
    ),
    "module_manifests": attrs.option(attrs.transition_dep(cfg = cpu_transition), default = None, doc = ""),
    "use_derived_apk": attrs.bool(default = False),
}

android_aar = prelude_rule(
    name = "android_aar",
    docs = """
        An `android_aar()` rule is used to generate an Android AAR.

        See the [official Android documentation](https://developer.android.com/studio/projects/android-library#aar-contents) for details about the `.aar` format.
    """,
    examples = """
        ```
        android_resource(
          name = 'res',
          res = 'res',
          assets = 'assets',
          package = 'com.example',
        )

        android_library(
          name = 'lib',
          srcs = glob(['**/*.java']),
        )

        android_aar(
          name = 'app',
          manifest_skeleton = 'AndroidManifestSkeleton.xml',
          deps = [
            ':res',
            ':lib',
          ],
        )
        ```
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "manifest_skeleton": attrs.source(
                doc = """
                The skeleton manifest file used to generate the final `AndroidManifest.xml` . May either be a file or an `android_manifest()` target.
            """,
            ),
            "build_config_values": attrs.list(
                attrs.string(),
                default = [],
                doc = """
                See the documentation on the values argument for `android_build_config()`.
            """,
            ),
            "include_build_config_class": attrs.bool(
                default = False,
                doc = """
                Whether to include the `BuildConfig` class files in the final .aar file. Needs
                 to be set to `True` if any build\\_config\\_values are specified.
                 This is normally only needed if the build tool that is consuming the .aar file does not generate
                 `BuildConfig` classes.
                 Note: the AAR format does not specify a way to pass defaults that should be injected into
                 the final `BuildConfig` class, therefore that information might need to be replicated
                 manually in the build that's consuming the .aar file.
            """,
            ),
            "deps": attrs.list(
                attrs.split_transition_dep(cfg = cpu_split_transition),
                default = [],
                doc = """
                List of build targets whose corresponding compiled Java code,
                 Android resources, and native libraries will be included in the AAR along with their transitive
                 dependencies. For compile time deps which should not be included in the final AAR,
                 use `provided_deps` instead.
                 * `android_library()` Will be included in the final `classes.jar`* `android_resource()` Will be included in the final `R.txt`,
                 `res/` and `assets/`* `android_build_config()` Will be included in the final `classes.jar`
                 if `include_build_config_class` is True
                 * `groovy_library()` Will be included in the final `classes.jar`* `java_library()` Will be included in the final `classes.jar`* `prebuilt_jar()` Will be included in the final `classes.jar`* `prebuilt_native_library()` Will be included in the final `jni/` or
                 `assets/` if `is_asset` is True
            """,
            ),
            "remove_classes": attrs.list(
                attrs.regex(),
                default = [],
                doc = """
                List of classes to remove from the output aar. It removes classes from the target's own sources,
                 and its dependencies.
            """,
            ),
            "build_config_values_file": attrs.option(attrs.source(), default = None),
            "cpu_filters": attrs.list(attrs.enum(TargetCpuType), default = ALL_CPU_FILTERS),
            "enable_relinker": attrs.bool(default = False),
            "excluded_java_deps": attrs.list(attrs.dep(), default = []),
            "extra_arguments": attrs.list(attrs.string(), default = []),
            "extra_kotlinc_arguments": attrs.list(attrs.arg(anon_target_compatible = True), default = []),
            "extra_relinker_outputs": attrs.list(attrs.string(), default = []),
            "preinline_ir_sonames": attrs.list(attrs.string(), default = []),
            # @oss-disable[end= ]: "gatorade_extra_args": attrs.list(attrs.arg(), default = [], doc = "Extra Gatorade cross-library step arguments"),
            # @oss-disable[end= ]: "gatorade_phases": attrs.set(attrs.enum(GatoradePhase), default = []),
            "hardcode_permissions_for_deterministic_output": attrs.option(
                attrs.bool(),
                default = None,
                doc = """
                If set to true, Buck hardcodes the permissions in order to ensures that all files have the same
                permissions regardless of the platform on which the zip was generated.
            """,
            ),
            "java_version": attrs.option(attrs.string(), default = None),
            "language": attrs.option(attrs.enum(JvmLanguage), default = None),
            "manifest": attrs.option(attrs.source(), default = None),
            "manifest_entries": attrs.dict(key = attrs.string(), value = attrs.any(), default = {}),
            "manifest_file": attrs.option(attrs.source(), default = None),
            "maven_coords": attrs.option(attrs.string(), default = None),
            "min_sdk_version": attrs.option(attrs.int(), default = None),
            "native_library_bolt_args": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.arg())), default = None),
            "native_library_merge_code_generator": attrs.option(attrs.exec_dep(), default = None),
            "native_library_merge_glue": attrs.option(attrs.split_transition_dep(cfg = cpu_split_transition), default = None),
            "native_library_merge_linker_args": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.arg())), default = None),
            "native_library_merge_linker_args_all": attrs.list(attrs.arg(), default = [], doc = "Extra linker arguments passed to all merged libraries."),
            "native_library_merge_map": attrs.option(attrs.dict(key = attrs.string(), value = attrs.list(attrs.regex()), sorted = False), default = None),
            "native_library_merge_non_asset_libs": attrs.bool(default = False),
            "native_library_merge_sequence": attrs.option(
                attrs.list(
                    attrs.one_of(
                        attrs.tuple(attrs.string(), attrs.list(attrs.regex())),
                        attrs.list(attrs.tuple(attrs.string(), attrs.list(attrs.regex()))),
                    ),
                ),
                default = None,
            ),
            "native_library_merge_sequence_blocklist": attrs.option(attrs.list(attrs.regex()), default = None),
            "package_asset_libraries": attrs.bool(default = True),
            "package_resources": attrs.bool(default = True),
            "proguard_config": attrs.option(attrs.source(), default = None),
            "relinker_extra_args": attrs.dict(
                key = attrs.string(),
                value = attrs.list(attrs.arg()),
                sorted = False,
                default = {},
                doc = "Per-library extra linker arguments passed when relinking, mapping sonames to lists of arguments.",
            ),
            "relinker_extra_args_all": attrs.list(attrs.arg(), default = [], doc = "Extra arguments passed when relinking all libraries."),
            "relinker_extra_deps": attrs.list(
                attrs.split_transition_dep(cfg = cpu_split_transition),
                default = [],
                doc = "Deps statically linked to every native lib by the relinker.",
            ),
            "relinker_whitelist": attrs.list(attrs.regex(), default = []),
            "required_for_source_only_abi": attrs.bool(default = False),
            "resources": attrs.list(attrs.source(), default = []),
            "resources_root": attrs.option(attrs.string(), default = None),
            "runtime_deps": attrs.list(attrs.dep(), default = []),
            "source": attrs.option(attrs.string(), default = None),
            "source_only_abi_deps": attrs.list(attrs.dep(), default = []),
            "srcs": attrs.list(attrs.source(), default = []),
            "strip_libraries": attrs.default_only(attrs.bool(default = not DISABLE_STRIPPING)),
            "target": attrs.option(attrs.string(), default = None),
            "_android_toolchain": toolchains_common.android(),
            "_cxx_toolchain": attrs.split_transition_dep(cfg = cpu_split_transition, default = "toolchains//:android-hack"),
            "_is_building_android_binary": attrs.default_only(attrs.bool(default = True)),
            "_java_toolchain": toolchains_common.java_for_android(),
        }
        | CPU_TRANSITION_ATTRS
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    )
    | jvm_common.abi_generation_mode()
    | jvm_common.annotation_processors()
    | jvm_common.plugins(),
)

android_app_modularity = prelude_rule(
    name = "android_app_modularity",
    docs = """
        An `android_app_modularity()` rule is used to determine the modular
        structure of an Android app. It defines how application modules are
        configured and which dependencies belong to each module, enabling
        dynamic delivery and on-demand loading of app features.
    """,
    examples = None,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "application_module_blocklist": attrs.option(attrs.list(attrs.dep()), default = None, doc = ""),
            "application_module_configs": attrs.dict(key = attrs.string(), value = attrs.list(attrs.dep()), sorted = False, default = {}, doc = ""),
            "application_module_dependencies": attrs.option(
                attrs.dict(key = attrs.string(), value = attrs.list(attrs.string()), sorted = False),
                default = None,
                doc = "",
            ),
            "deps": attrs.list(attrs.dep(), default = [], doc = ""),
            "no_dx": attrs.list(
                attrs.dep(),
                default = [],
                doc = """List of dependency targets whose Java code should be excluded from the DEX files in the final APK. \
The classes from these targets will not be dexed, but their other resources will still be included. \
This might be useful to resolve duplicate class errors when multiple dependencies provide the same class. \
See [this document](https://www.internalfb.com/intern/staticdocs/confucius/docs/notes/dev/projects/android/resolving_duplicate_classes_with_no_dx/) \
for how to resolve duplicate classes using this attribute.""",
            ),
            "should_include_classes": attrs.bool(default = True, doc = ""),
            "should_include_libraries": attrs.bool(default = False, doc = ""),
            "_android_toolchain": toolchains_common.android(),
            "_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
        }
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    ),
)

android_binary = prelude_rule(
    name = "android_binary",
    docs = """
        An `android_binary()` rule is used to generate an Android APK.
    """,
    examples = None,
    further = None,
    attrs = ANDROID_BINARY_ATTRS,
    cfg = constraint_overrides.transition,
)

android_build_config = prelude_rule(
    name = "android_build_config",
    docs = """
        An `android_build_config()` rule is used to generate
        a `BuildConfig` class with global configuration variables
        that other `android_library()` rules can compile against.
        Currently, the only variable exposed by `BuildConfig` is
        a global `boolean` named `DEBUG`, much like
        the `BuildConfig.java` generated by the official Android
        build tools based on Gradle.

        The fields in the generated `BuildConfig` class will
        be non-constant-expressions (see [JLS 15.28](http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.28)).
        However, if `BuildConfig` is packaged into an APK, it will
        be replaced with a new version where:
        * The fields will be set to literal values (i.e., constant expressions).
         * The `boolean BuildConfig.DEBUG` field will correspond to
        that of the `package_type` argument to the `android_binary()` rule
        that is packaging it.

        This transformation is done before ProGuard is applied (if applicable), so
        that it can propagate constants from `BuildConfig` and eliminate
        dead code.
    """,
    examples = """
        Here is an example of an `android_build_config()` rule that
        is transitively included by both *debug* and *release* versions
        of an `android_binary()` rule. The value
        of `com.example.pkg.BuildConfig.DEBUG` will be different in each APK
        even though they both transitively depend on the same `:build_config` rule.

        ```
        android_build_config(
          name = 'build_config',
          package = 'com.example.pkg',
          values = [
            'String COMMIT_ID = "0000000000000000000000000000000000000000"',
          ],
        )

        # The .java files in this library may contain references to the boolean
        # com.example.pkg.BuildConfig.DEBUG because :build_config is in the deps.
        # It could also reference BuildConfig.COMMIT_ID.
        android_library(
          name = 'mylib',
          srcs = glob(['src/**/*.java']),
          deps = [
            ':build_config',
          ],
        )

        android_binary(
          name = 'debug',
          package_type = 'DEBUG',
          keystore =  '//keystores:debug',
          manifest = 'AndroidManifest.xml',
          target = 'Google Inc.:Google APIs:19',
          deps = [
            ':mylib',
          ],
        )

        # The contents of the file generated by this rule might be:
        #
        # String COMMIT_ID = "7bf804bdf71fdbfc99cce3b155b3643f022c6fa4"
        #
        # Note that the output of :build_config_release_values will be cached by Buck.
        # Assuming that generate_release_build_config.py depends on state that is not
        # expressed by its deps (which violates a fundamental invariant in Buck!), a
        # workaround is to ensure that the inputs to :build_config_release_values are
        # changed in some way before :release is built to ensure that the output from
        # :build_config_release_values is not pulled from cache. For example:
        #
        # $ buck build :release
        # $ uuidgen > dummy_state_file.txt
        # $ buck build :release
        #
        # This makes sure that generate_release_build_config.py is re-run before
        # :release is rebuilt. This is much cheaper than deleting your build cache
        # before rebuilding.
        genrule(
          name = 'build_config_release_values',
          srcs = [ 'generate_release_build_config.py', 'dummy_state_file.txt' ],
          bash = 'generate_release_build_config.py $OUT',
          out = 'build_config_release_values.txt',
        )

        android_binary(
          name = 'release',
          package_type = 'RELEASE',
          keystore =  '//keystores:release',
          manifest = 'AndroidManifest.xml',
          target = 'Google Inc.:Google APIs:19',
          build_config_values_file = ':build_config_release_values',
          deps = [
            ':mylib',
          ],
        )
        ```
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "package": attrs.string(
                default = "",
                doc = """
                Name of the Java package to use in the generated `BuildConfig.java` file.
                 Most developers set this to the application id declared in the manifest
                 via `<manifest package="APP_ID">`.
                 Example: `com.facebook.orca`.
            """,
            ),
            "values": attrs.list(
                attrs.string(),
                default = [],
                doc = """
                List of strings that defines additional fields (and values) that should be declared in the
                 generated `BuildConfig.java` file. Like `DEBUG`, the values will be
                 non-constant-expressions that evaluate to the value specified in the file at compilation
                 time.
                 To override the values in an APK, specify build\\_config\\_values or build\\_config\\_values\\_file in `android_binary()`.
            """,
            ),
            "values_file": attrs.option(
                attrs.source(),
                default = None,
                doc = """
                Optional path to a file that defines additional fields (and values) that should be declared in the
                 generated `BuildConfig.java` file. Like `DEBUG`, the values will be
                 non-constant-expressions that evaluate to the value specified in the file at compilation
                 time.
                 To override the values in an APK, specify build\\_config\\_values or build\\_config\\_values\\_file in `android_binary()`.

                 Note that values\\_file can be a generated file, as can build\\_config\\_values\\_file as
                 demonstrated in the example below.
            """,
            ),
            "_android_toolchain": toolchains_common.android(),
            "_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
            "_is_building_android_binary": is_building_android_binary_attr(),
            "_java_toolchain": toolchains_common.java_for_android(),
        }
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    ),
)

android_bundle = prelude_rule(
    name = "android_bundle",
    docs = """
        An `android_bundle()` rule is used to generate an Android App Bundle
        (AAB). It shares most attributes with `android_binary()`, but produces
        an AAB file instead of an APK. App Bundles are the recommended
        publishing format for Google Play, enabling optimized APK delivery
        per device configuration.
    """,
    examples = None,
    further = None,
    attrs = ANDROID_BUNDLE_ATTRS,
)

android_instrumentation_apk = prelude_rule(
    name = "android_instrumentation_apk",
    docs = """
        An `android_instrumentation_apk()` rule is used to generate
        an Android Instrumentation APK.

        Android's [Testing Fundamentals](http://developer.android.com/tools/testing/testing_android.html) documentation includes a diagram that shows
        the relationship between an "application package" and a "test package"
        when running a test. This rule corresponds to a test package. Note
        that a test package has an interesting quirk where it is *compiled
        against* an application package, but *must not include* the
        resources or Java classes of the application package. Therefore, this
        class takes responsibility for making sure the appropriate bits are
        excluded. Failing to do so will generate mysterious runtime errors
        when running the test.
    """,
    examples = """
        Here is an example of an `android_instrumentation_apk()` rule that tests an `android_binary()`, and depends on a test
        package.

        ```
        android_library(
          name = 'test',
          srcs = glob(['test/**/*.java']),
        )

        android_binary(
          name = 'messenger',
          manifest = 'AndroidManifest.xml',
          keystore = '//keystores:prod',
          package_type = 'release',
          proguard_config = 'proguard.cfg',
          deps = [
            ...
          ],
        )

        # Building this rule will produce a file named messenger_test.apk
        android_instrumentation_apk(
          name = 'messenger_test',
          manifest = 'AndroidInstrumentationManifest.xml',
          apk = ':messenger',
          deps = [
            ':test',
          ],
        )
        ```
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        android_common.manifest_apk_arg()
        | {
            "apk": attrs.dep(
                doc = """
                APK build target, which should be used for the instrumentation APK.
                 Can be either an `android_binary()` or an `apk_genrule()`.
            """,
            ),
        }
        | android_common.deps_apk_arg()
        | {
            "cpu_filters": attrs.list(attrs.enum(TargetCpuType), default = []),
            "deps": attrs.list(
                attrs.split_transition_dep(cfg = cpu_split_transition),
                default = [],
                doc = """
                List of build targets whose corresponding compiled Java code,
                 Android resources, and native libraries will be included in the APK.
                 From the transitive closure of these dependencies, the outputs of rules of the following type will be included in the APK:
                 * `android_library()`* `android_resource()`* `cxx_library()`* `groovy_library()`* `java_library()`* `java_binary()`* `prebuilt_jar()`* `ndk_library()`* `prebuilt_native_library()`
            """,
            ),
            "disable_pre_dex": attrs.bool(default = False),
            "enable_bootstrap_dexes": attrs.bool(default = False),
            "includes_vector_drawables": attrs.bool(default = False),
            "is_self_instrumenting": attrs.bool(default = False),
            "manifest": attrs.option(
                attrs.one_of(attrs.transition_dep(cfg = cpu_transition), attrs.source()),
                default = None,
                doc = """
                Relative path to the Android manifest for the APK. The common
                 case is that the manifest will be in the same directory as the
                 rule, in which case this will simply be
                 `'AndroidManifest.xml'`, but it can also reference
                 an `android_manifest()` rule.

                 Prefer using `manifest_skeleton`, which performs merging automatically.
                 Exactly one of `manifest` and `manifest_skeleton` must be set.
            """,
            ),
            "manifest_skeleton": attrs.option(
                attrs.one_of(attrs.transition_dep(cfg = cpu_transition), attrs.source()),
                default = None,
                doc = """
                Relative path to the skeleton Android manifest for the APK.
                 An `android_manifest()` will be created automatically to merge
                 all manifests from libraries and resources going into the app.
                 The common case is that the manifest will be in the same directory as the
                 rule, in which case this will simply be
                 `'AndroidManifest.xml'`.

                 Exactly one of `manifest` and `manifest_skeleton` must be set.
            """,
            ),
            "min_sdk_version": attrs.option(attrs.int(), default = None),
            "multidex_min_api": attrs.option(attrs.string(), default = None),
            "preprocess_java_classes_bash": attrs.option(attrs.arg(), default = None),
            "preprocess_java_classes_deps": attrs.list(attrs.dep(), default = []),
            "primary_dex_patterns": attrs.list(attrs.string(), default = []),
            "use_split_dex": attrs.option(attrs.bool(), default = None),
            "_android_toolchain": toolchains_common.android(),
            "_cxx_toolchain": attrs.split_transition_dep(cfg = cpu_split_transition, default = "toolchains//:android-hack"),
            "_dex_toolchain": toolchains_common.dex(),
            "_exec_os_type": buck.exec_os_type_arg(),
            "_is_building_android_binary": attrs.default_only(attrs.bool(default = True)),
            "_java_toolchain": toolchains_common.java_for_android(),
        }
        | CPU_TRANSITION_ATTRS
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    ),
)

android_instrumentation_test = prelude_rule(
    name = "android_instrumentation_test",
    docs = """
        An `android_instrumentation_test()` rule is used to define
         apks that should be used to run Android instrumentation tests.
    """,
    examples = """
        Here is an example of an `android_instrumentation_test()`
         rule that tests an `android_binary()`.

        ```
        android_binary(
          name = 'messenger',
          manifest = 'AndroidManifest.xml',
          keystore = '//keystores:prod',
          package_type = 'release',
          proguard_config = 'proguard.cfg',
          deps = [
            ...
          ],
        )

        android_instrumentation_apk(
          name = 'messenger_test',
          manifest = 'AndroidInstrumentationManifest.xml',
          apk = ':messenger',
          deps = [
            ...
          ],
        )

        android_instrumentation_test(
          name = 'messenger_instrumentation_test',
          apk = ':messenger_test',
        )
        ```
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        buck.inject_test_env_arg()
        | {
            "apk": attrs.dep(
                doc = """
                The APK containing the tests. Can be an `android_binary()`,
                 an `apk_genrule()` or an `android_instrumentation_apk()`.
            """,
            ),
        }
        | buck.test_label_arg()
        | buck.test_rule_timeout_ms()
        | buck.licenses_arg()
        | buck.contacts_arg()
        | {
            "clear_package_data": attrs.bool(
                default = False,
                doc = """
                Runs `pm clear` on the app and test packages before the test run if set to True.
            """,
            ),
            "collect_tombstones": attrs.bool(
                default = False,
                doc = """
                Checks whether the test generated any tombstones, and downloads them from the emulator if true.
            """,
            ),
            "disable_animations": attrs.bool(
                default = False,
                doc = """
                Disables animations on the emulator if set to True.
            """,
            ),
            "env": attrs.dict(key = attrs.string(), value = attrs.arg(), sorted = False, default = {}),
            "extra_instrumentation_args": attrs.option(attrs.dict(key = attrs.string(), value = attrs.arg()), default = None),
            "instrumentation_test_listener": attrs.option(attrs.exec_dep(), default = None),
            "instrumentation_test_listener_class": attrs.option(attrs.string(), default = None),
            "is_self_instrumenting": attrs.bool(default = False),
            "log_extractors": attrs.dict(key = attrs.string(), value = attrs.string(), sorted = False, default = {}),
            "meta_internal_extra_params": META_INTERNAL_EXTRA_PARAMS,
            "re_caps": RE_CAPS,
            "re_use_case": RE_USE_CASE,
            "record_video": attrs.bool(default = False, doc = "Record video of test run and collect it as TRA"),
            "_android_emulators": attrs.option(
                attrs.transition_dep(cfg = clear_platform_transition, providers = [LocalResourceInfo]),
                default = None,
                doc = """
                If provided, local resource of "android_emulators" type will be required to run this test locally and this target will be used to manage it. If omitted, local resource of "android_emulators" type will be ignored even if requested by the test runner.
            """,
            ),
            "_android_toolchain": toolchains_common.android(),
            "_exec_os_type": buck.exec_os_type_arg(),
            "_java_test_toolchain": toolchains_common.java_for_host_test(),
            "_java_toolchain": toolchains_common.java_for_android(),
            "_test_srcs": attrs.list(attrs.source(allow_directory = True), default = []),
        }
        | test_common.attributes()
    ),
)

android_library = prelude_rule(
    name = "android_library",
    docs = """
        An `android_library()` rule is used to define a set of Java files
        that can be compiled together against the Android SDK. The main output of an
         `android_library()` rule is a single JAR file containing all of the
        compiled class files and resources.
    """,
    examples = """
        An `android_library` rule used in concert with an
         `android_resource()` rule.
        This would be a common arrangement for a standard Android Library project
        as defined by
         [http://developer.android.com/tools/projects/index.html](http://developer.android.com/tools/projects/index.html)

        ```
        android_resource(
          name = 'res',
          res = 'res',
          package = 'com.example',
        )

        android_library(
          name = 'my_library',
          srcs = glob(['src/**/*.java']),
          deps = [
            ':res',
          ],
        )
        ```
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "srcs": attrs.list(
                attrs.source(),
                default = [],
                doc = """
                The set of `.java` files to compile for this rule.
            """,
            ),
            "resources": attrs.list(
                attrs.source(),
                default = [],
                doc = """
                Static files to include among the compiled `.class`
                 files. These files can be loaded via [Class.getResource()](http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getResource(java.lang.String)).

                **Note:** Buck uses the `src_roots` property in
                 `.buckconfig`
                 to help determine where resources should be placed within the generated JAR file.
            """,
            ),
        }
        | android_common.manifest_arg()
        | {
            "deps": attrs.list(
                attrs.dep(),
                default = [],
                doc = """
                Rules (usually other `android_library` rules)
                 that are used to generate the classpath required to compile this
                 `android_library`.
            """,
            ),
            "extra_arguments": attrs.list(
                attrs.string(),
                default = [],
                doc = """
                List of additional arguments to pass into the Java compiler. These
                 arguments follow the ones specified in `.buckconfig`.
            """,
            ),
            "extra_kotlinc_arguments": attrs.list(
                attrs.arg(anon_target_compatible = True),
                default = [],
                doc = """
                List of additional arguments to pass into the Kotlin compiler.
            """,
            ),
            "source": attrs.option(
                attrs.string(),
                default = None,
                doc = """
                Specifies the version of Java (as a string) to interpret source
                 files as.
                 Overrides the value in "source\\_level" in the "java" section
                 of `.buckconfig`.
            """,
            ),
            "target": attrs.option(
                attrs.string(),
                default = None,
                doc = """
                Specifies the version of Java (as a string) for which to
                 generate code.
                 Overrides the value in "target\\_level" in the "java" section
                 of `.buckconfig`.
            """,
            ),
        }
        | jvm_common.annotation_processors()
        | jvm_common.exported_deps()
        | jvm_common.provided_deps()
        | jvm_common.exported_provided_deps()
        | buck.provided_deps_query_arg()
        | jvm_common.abi_generation_mode()
        | jvm_common.source_only_abi_deps()
        | jvm_common.required_for_source_only_abi()
        | jvm_common.k2()
        | jvm_common.kotlin_compiler_plugins()
        | jvm_common.incremental()
        | jvm_common.kotlincd_content_based_paths()
        | jvm_common.enable_used_classes()
        | jvm_common.classic_java_content_based_paths()
        | android_common.patches_system_module_arg()
        | {
            "android_optional_jars": attrs.option(attrs.list(attrs.dep()), default = None),
            "capabilities_registrations": attrs.option(attrs.list(attrs.any()), default = None),
            "friend_paths": jvm_common.friend_paths_attr(),
            "jar_postprocessor": attrs.option(attrs.exec_dep(), default = None),
            "java_version": attrs.option(attrs.string(), default = None),
            "language": attrs.option(attrs.enum(JvmLanguage), default = None),
            "manifest_file": attrs.option(attrs.source(), default = None),
            "maven_coords": attrs.option(attrs.string(), default = None),
            "proguard_config": attrs.option(attrs.source(), default = None),
            "remove_classes": attrs.list(
                attrs.regex(),
                default = [],
                doc = """
                List of classes to remove from the output jar. It only removes classes from the target's own
                 sources, not from any of its dependencies.
            """,
            ),
            "resources_root": attrs.option(attrs.string(), default = None),
            "runtime_deps": attrs.list(attrs.dep(), default = []),
            VALIDATION_DEPS_ATTR_NAME: attrs.set(attrs.dep(), sorted = True, default = []),
            "_android_toolchain": toolchains_common.android(),
            "_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
            "_dex_min_sdk_version": attrs.default_only(attrs.option(attrs.int(), default = dex_min_sdk_version())),
            "_dex_toolchain": toolchains_common.dex(),
            "_exec_os_type": buck.exec_os_type_arg(),
            "_is_building_android_binary": is_building_android_binary_attr(),
            "_java_toolchain": toolchains_common.java_for_android(),
            "_kotlin_toolchain": toolchains_common.kotlin_for_android(),
        }
    )
    | jvm_common.plugins()
    | validation_common.attrs_validators_arg()
    | validation_common.validation_specs_arg()
    | buck.licenses_arg()
    | buck.labels_arg()
    | buck.contacts_arg(),
)

android_manifest = prelude_rule(
    name = "android_manifest",
    docs = """
        An `android_manifest()` rule is used to generate an
         [Android
        Manifest](http://developer.android.com/guide/topics/manifest/manifest-intro.html) to be used by `android_binary()` and `android_aar()` rules. This
        rule takes a skeleton manifest, and merges it with manifests found in any deps.
    """,
    examples = """
        Here's an example of an `android_manifest()` that has no deps.

        ```
        android_manifest(
          name = 'my-manifest',
          skeleton = 'AndroidManifestSkeleton.xml',
        )
        ```

         This is what `AndroidManifestSkeleton.xml` looks like.

        ```
        <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                  package="com.example"
                  android:versionCode="1"
                  android:versionName="1.0">

            <uses-sdk targetSdkVersion="19" minSdkVersion="17"/>
            <application
                android:label="@string/app_name"
                android:icon="@drawable/ic_launcher">
                <activity
                    android:name="MyActivity"
                    android:label="@string/app_name">
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN"/>
                        <category android:name="android.intent.category.LAUNCHER"/>
                    </intent-filter>
                </activity>
            </application>
        </manifest>
        ```

         You could also use a `genrule()` to generate the manifest file and reference the
         `build target` in the `skeleton` argument.
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "skeleton": attrs.source(
                doc = """
                Either a `build target` or a path to a file representing the manifest that
                 will be merged with any manifests associated with this rule's `deps`.
            """,
            ),
            "deps": attrs.list(
                attrs.dep(),
                default = [],
                doc = """
                A collection of dependencies that includes android\\_library rules. The manifest files of the
                 `android_library()` rules will be filtered out to become dependent source files for
                 the manifest.
            """,
            ),
            "_android_toolchain": toolchains_common.android(),
        }
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    ),
)

android_prebuilt_aar = prelude_rule(
    name = "android_prebuilt_aar",
    docs = """
        An `android_prebuilt_aar()` rule takes an `.aar` file and
        makes it available as an Android dependency. As expected,
        an `android_binary()` that transitively depends on
        an `android_prebuilt_aar()` will include its contents in the generated APK.

        See the [official Android documentation](https://developer.android.com/studio/projects/android-library#aar-contents) for details about the `.aar` format.
    """,
    examples = """
        ```
        android_prebuilt_aar(
          name = 'play-services',
          aar = 'play-services-4.0.30.aar',
          source_jar = 'play-services-4.0.30-sources.jar',
          javadoc_url = 'file:///opt/android-sdk/extras/google/google_play_services/docs/reference',
        )

        android_library(
          name = 'lib',
          # This Java code can compile against Play services and reference its resources.
          srcs = glob(['*.java']),
          deps = [ ':play-services' ],
        )
        ```
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "aar": attrs.source(
                doc = """
                Path to the `.aar` file. This may also be a build target to
                 a rule (such as a `genrule()`) whose output is
                 an `.aar` file.
            """,
            ),
            "source_jar": attrs.option(
                attrs.source(),
                default = None,
                doc = """
                Path to a JAR file that contains the `.java` files to create
                 the `.class` in the `aar`. This is frequently
                 provided for debugging purposes.
            """,
            ),
            "javadoc_url": attrs.option(
                attrs.string(),
                default = None,
                doc = """
                URL to the Javadoc for the `.class` files in the
                 `aar`.
            """,
            ),
            "use_system_library_loader": attrs.bool(
                default = False,
                doc = """
                If this `.aar` file contains native prebuilt `.so` libraries and the
                 Java code uses these libraries via a call to `System.loadLibrary()`, then many
                 optimizations—such as exopackage, compression, or asset packaging—may not be compatible with these prebuilt libs.
                 Setting this parameter to `True` causes all of these optimizations to skip the prebuilt `.so`
                 files originating from this `.aar` file. The `.so` files will always be packaged directly into
                 the main `.apk`.
            """,
            ),
            "deps": attrs.list(
                attrs.dep(),
                default = [],
                doc = """
                Dependencies of this prebuilt AAR. Listed deps are automatically exported to consumers of this rule
                 and are used to resolve the transitive classpath for desugaring. Use this to specify libraries that
                 the `.aar` depends on at compile time or runtime but are not bundled within the `.aar` itself.
            """,
            ),
            "desugar_deps": attrs.list(attrs.dep(), default = []),
            "dex_weight_factor": attrs.int(default = 1),
            "for_primary_apk": attrs.bool(default = False),
            "maven_coords": attrs.option(attrs.string(), default = None),
            "required_for_source_only_abi": attrs.bool(default = True),
            "_android_toolchain": toolchains_common.android(),
            "_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
            "_dex_min_sdk_version": attrs.default_only(attrs.option(attrs.int(), default = dex_min_sdk_version())),
            "_dex_toolchain": toolchains_common.dex(),
            "_exec_os_type": buck.exec_os_type_arg(),
            "_is_building_android_binary": attrs.default_only(attrs.bool(default = False)),
            "_java_toolchain": toolchains_common.java_for_android(),
        }
        | jvm_common.classic_java_content_based_paths()
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    ),
)

android_resource = prelude_rule(
    name = "android_resource",
    docs = """
        An `android_resource()` rule is used to bundle Android resources
        that are traditionally stored in `res` and `assets` directories.

        The output of an `android_resource()` is an `R.txt` file
        generated via `aapt --output-text-symbols`.
    """,
    examples = """
        Most of the time, an `android_resource` rule defines only `name`, `res`, and `package`. By convention,
        such simple rules are often named `res`:

        ```
        android_resource(
          name = 'res',
          res = subdir_glob([('res', '**')]),
          package = 'com.example',
        )
        ```
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "res": attrs.option(
                attrs.one_of(attrs.source(), attrs.dict(key = attrs.string(), value = attrs.source(), sorted = True)),
                default = None,
                doc = """
                A dictionary mapping relative resource paths to either
                 the resource files or the build targets that generate them.
                 The `subdir_glob` function
                 can be used to generate dictionaries based on a directory structure of files checked
                 into the repository. Alternatively, this can be a path to a directory containing
                 Android resources, although this option is deprecated and might be removed in the future.
            """,
            ),
            "unused_resource_dep_validation_has_non_xml_resources": attrs.option(attrs.bool(), default = None),
            "package": attrs.option(
                attrs.string(),
                default = None,
                doc = """
                Java package for the `R.java` file that will be generated for these
                 resources.
            """,
            ),
            "assets": attrs.option(
                attrs.one_of(attrs.source(), attrs.dict(key = attrs.string(), value = attrs.source(), sorted = True)),
                default = None,
                doc = """
                A dictionary mapping relative asset paths to either
                 the asset files or the build targets that generate them.
                 The `subdir_glob` function
                 can be used to generate dictionaries based on a directory structure of files checked
                 into the repository. Alternatively, this can be a path to a directory containing
                 Android assets, although this option is deprecated and might be removed in the future.
            """,
            ),
            "project_res": attrs.option(
                attrs.source(),
                default = None,
                doc = """
                A directory containing resources to be used for project generation.
                 If not provided, defaults to whatever the build uses.
            """,
            ),
            "project_assets": attrs.option(
                attrs.source(),
                default = None,
                doc = """
                A directory containing assets to be used for project generation.
                 If not provided, defaults to whatever the build uses.
            """,
            ),
        }
        | android_common.manifest_arg()
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
        | {
            "allowlisted_locales": attrs.option(attrs.set(attrs.string(), sorted = False), default = None),
            "assets": attrs.option(
                attrs.one_of(attrs.source(allow_directory = True), attrs.dict(key = attrs.string(), value = attrs.source(), sorted = True)),
                default = None,
                doc = """
                A dictionary mapping relative asset paths to either
                 the asset files or the build targets that generate them.
                 The `subdir_glob` function
                 can be used to generate dictionaries based on a directory structure of files checked
                 into the repository. Alternatively, this can be a path to a directory containing
                 Android assets, although this option is deprecated and might be removed in the future.
            """,
            ),
            "deps": attrs.list(
                attrs.dep(),
                default = [],
                doc = """
                Other `android_resource` rules to include via `-S` when
                 running `aapt`.
            """,
            ),
            "has_whitelisted_strings": attrs.bool(default = False),
            "project_assets": attrs.option(
                attrs.source(allow_directory = True),
                default = None,
                doc = """
                A directory containing assets to be used for project generation.
                 If not provided, defaults to whatever the build uses.
            """,
            ),
            "project_res": attrs.option(
                attrs.source(allow_directory = True),
                default = None,
                doc = """
                A directory containing resources to be used for project generation.
                 If not provided, defaults to whatever the build uses.
            """,
            ),
            "res": attrs.option(
                attrs.one_of(attrs.source(allow_directory = True), attrs.dict(key = attrs.string(), value = attrs.source(), sorted = True)),
                default = None,
                doc = """
                A dictionary mapping relative resource paths to either
                 the resource files or the build targets that generate them.
                 The `subdir_glob` function
                 can be used to generate dictionaries based on a directory structure of files checked
                 into the repository. Alternatively, this can be a path to a directory containing
                 Android resources, although this option is deprecated and might be removed in the future.
            """,
            ),
            "_android_toolchain": toolchains_common.android(),
            "_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
            "_is_building_android_binary": attrs.default_only(attrs.bool(default = False)),
            "_java_toolchain": toolchains_common.java_for_android(),
        }
    ),
)

apk_genrule = prelude_rule(
    name = "apk_genrule",
    docs = """
        An `apk_genrule()` rule is used to post-process an APK. What
        separates an apk\\_genrule from a genrule is apk\\_genrules are known by BUCK to
        produce APKs, so commands like `buck install` or
         `buck uninstall` still work. Additionally,
         `apk_genrule()` rules can be inputs to other
         `apk_genrule()` rules.
    """,
    examples = """
        Here is an example of a couple `apk_genrule()` open up an APK, do
        some super signing, and then zipalign that APK again.

        ```
        # Building this rule will produce a file named messenger.apk.
        android_binary(
          name = 'messenger',
          manifest = 'AndroidManifest.xml',
          target = 'Google Inc.:Google APIs:16',
          keystore = '//keystores:prod',
          package_type = 'release',
          proguard_config = 'proguard.cfg',
          deps = [
            ':res',
            ':src',
          ],
        )

        apk_genrule(
          name = 'messenger_super_sign_unalign',
          apk = ':messenger',
          bash = '$(exe //java/com/facebook/sign:super_sign) --input $APK --output $OUT',
          cmd_exe = '$(exe //java/com/facebook/sign:super_sign) --input %APK% --output %OUT%',
          out = 'messenger_super_sign_unalign.apk',
        )

        apk_genrule(
          name = 'messenger_super_sign',
          apk = ':messenger_super_sign_unalign',
          bash = '$ANDROID_HOME/tools/zipalign -f 4 $APK $OUT',
          cmd_exe = '%ANDROID_HOME%\\tools\\zipalign -f 4 %APK% %OUT%',
          out = 'messenger_super_sign.apk',
        )
        ```
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "apk": attrs.option(
                attrs.dep(),
                default = None,
                doc = """
                The input `android_binary()` rule. The path to the APK can be
                 accessed with the `$APK` shell variable. Only one of `apk` or
                 `aab` can be provided.
            """,
            ),
            "keystore": attrs.option(attrs.dep(), default = None),
        }
        | genrule_common.srcs_arg()
        | genrule_common.cmd_arg()
        | genrule_common.bash_arg()
        | genrule_common.cmd_exe_arg()
        | genrule_common.type_arg()
        | genrule_common.weight_arg()
        | {
            "out": attrs.option(
                attrs.string(),
                default = None,
                doc = """
                The name of the output file or directory. The complete path to this
                 argument is provided to the shell command through
                 the `OUT` environment variable. Only one of `out`
                 or `outs` may be present.

                For an apk_genrule the output should be a '.apk' or '.aab' file.
            """,
            ),
        }
        | genrule_common.environment_expansion_separator()
        | {
            "aab": attrs.option(
                attrs.dep(),
                default = None,
                doc = """
                The input `android_binary()` rule. The path to the AAB can be
                 accessed with the `$AAB` shell variable. Only one of `apk` or
                 `aab` can be provided.
            """,
            ),
            "cacheable": attrs.option(attrs.bool(), default = None),
            "default_outs": attrs.option(attrs.set(attrs.string(), sorted = False), default = None),
            "enable_sandbox": attrs.option(attrs.bool(), default = None),
            "is_cacheable": attrs.bool(default = False),
            "outs": attrs.option(attrs.dict(key = attrs.string(), value = attrs.set(attrs.string(), sorted = False), sorted = False), default = None),
            "remote": attrs.option(attrs.bool(), default = None),
            "type": attrs.string(default = "apk"),
            "use_derived_apk": attrs.bool(default = False),
            "_android_toolchain": toolchains_common.android(),
            "_exec_os_type": buck.exec_os_type_arg(),
            "_java_toolchain": toolchains_common.java_for_android(),
        }
        | genrule_attributes()
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    ),
)

gen_aidl = prelude_rule(
    name = "gen_aidl",
    docs = """
        A `gen_aidl()` rule is used to generate `.java` files
        from `.aidl` files.
    """,
    examples = """
        ```
        android_library(
          name = 'lib',
          srcs = glob(['**/*.java']) + [':aidl'],
          manifest = '//res/org/opencv:manifest',
          deps = [
            '//res/org/opencv:res',
          ],
          visibility = [ 'PUBLIC' ],
        )

        gen_aidl(
            name = 'aidl',
            aidl = 'engine/OpenCVEngineInterface.aidl',
            import_path = 'java/',
        )
        ```
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "aidl": attrs.source(
                doc = """
                The path to an `.aidl` file to convert to a
                 `.java` file.
            """,
            ),
            "import_path": attrs.string(
                default = "",
                doc = """
                The search path for import statements for the aidl command.
                 (This is the `-I` argument when invoking aidl
                 from the command line. For many apps it will be the base dir where all
                 aidl files are, with project root as its parent,
                 e.g. `app/src/main/aidl`.). This is the same as the path to the
                 `aidl` file relative to what would be returned from `root`.
            """,
            ),
            "import_paths": attrs.list(
                attrs.arg(),
                default = [],
                doc = """
                A list of additional import statements for the aidl command.
                 (This appends an `-I` argument for each of the provided paths when
                 invoking aidl from the command line.
            """,
            ),
            "aidl_srcs": attrs.set(
                attrs.source(),
                sorted = True,
                default = [],
                doc = """
                Path to `.aidl` files the target `aidl` file imports.
            """,
            ),
            "deps": attrs.list(
                attrs.dep(),
                default = [],
                doc = """
                A list of rules that must be built before this rule.
            """,
            ),
            "_aidl_toolchain": toolchains_common.android_aidl(),
            "_exec_os_type": buck.exec_os_type_arg(),
            "_java_toolchain": toolchains_common.java_for_android(),
        }
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    ),
)

keystore = prelude_rule(
    name = "keystore",
    docs = """
        A `keystore()` contains the data for a key pair
        created by the `keytool` executable that comes
        with the JDK. This is a required input for an `android_binary()` rule.
    """,
    examples = None,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "store": attrs.source(
                doc = """
                The path to the file that contains the key.
                 This is the path that was passed as the `-keystore` argument
                 when you ran `keytool`.
            """,
            ),
            "properties": attrs.source(
                doc = """
                The path to the `.properties` file that contains the following values:

                ```
                # The value that you passed as the argument to -alias
                # when you ran keytool.
                key.alias=my_alias

                # The value that you entered in response to
                # the "Enter keystore password:" prompt.
                key.store.password=store_password

                # The value that you entered in response to
                # the "Enter key password for <my_alias>" prompt.
                key.alias.password=alias_password
                ```
            """,
            ),
            "deps": attrs.list(attrs.dep(), default = []),
        }
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    ),
)

prebuilt_native_library = prelude_rule(
    name = "prebuilt_native_library",
    docs = """
        A `prebuilt_native_library()` rule is used to bundle native libraries
        (i.e., `.so` files) for Android.
    """,
    examples = """
        Most of the time, a `prebuilt_native_library` is private to the `android_library()` that uses it:

        ```
        prebuilt_native_library(
          name = 'native_libs',
          native_libs = 'libs',
        )

        android_library(
          name = 'my_lib',
          srcs = glob(['*.java']),
          deps = [
            ':native_libs',
          ],
        )
        ```
    """,
    further = None,
    attrs = (
        # @unsorted-dict-items
        {
            "native_libs": attrs.source(
                allow_directory = True,
                doc = """
                Path to a directory containing native libraries.
                 This directory has subdirectories for different architectures,
                 such as `armeabi` and `armeabi-v7a`.
            """,
            ),
            "is_asset": attrs.bool(
                default = False,
                doc = """
                Normally native shared objects end up in a directory in the root of the APK
                 named `lib/`. If this parameter is set to `True`, then
                 these objects are placed in `assets/lib/`. Placing shared objects in
                 a non-standard location prevents Android from extracting them to the device's
                 internal storage.
            """,
            ),
            "has_wrap_script": attrs.bool(
                default = False,
                doc = """
                When using an exopackage, if this
                 parameter is set to `True`, then the libraries for this rule are
                 included in the primary APK even if native libraries would otherwise not be
                 placed in it. This is intended for a native library directory that contains a
                 [wrap.sh](https://developer.android.com/ndk/guides/wrap-script)
                 script, which must be included in the primary APK to take effect. Only one
                 of `is_asset` and `has_wrap_script` can be set for a rule.
            """,
            ),
            "deps": attrs.list(attrs.dep(), default = []),
        }
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    ),
)

robolectric_test = prelude_rule(
    name = "robolectric_test",
    docs = """
        A `robolectric_test()` rule is used to define a set of
         `.java` files that contain tests to run via JUnit
        with Robolectric test runner. It extends from `java_test()` rule.
    """,
    examples = None,
    further = None,
    attrs = (
        # @unsorted-dict-items
        buck.inject_test_env_arg()
        | {
            "android_optional_jars": attrs.option(attrs.list(attrs.dep()), default = None),
            "compiled_resource_apks": attrs.list(attrs.source(), default = []),
            "cxx_library_allowlist": attrs.list(
                attrs.dep(),
                default = [],
                doc = """
                List of cxx_library targets to build, if use_cxx_libraries is true.
                This can be useful if some dependencies are Android-only and won't build for the test host platform.
            """,
            ),
            "deps": attrs.list(attrs.dep(), default = []),
            "discover_all_test_classes": attrs.bool(default = False),
            "env": attrs.dict(key = attrs.string(), value = attrs.arg(), sorted = False, default = {}),
            "exported_deps": attrs.list(attrs.dep(), default = []),
            "exported_provided_deps": attrs.list(attrs.dep(), default = []),
            "extra_arguments": attrs.list(attrs.string(), default = []),
            "extra_kotlinc_arguments": attrs.list(
                attrs.arg(anon_target_compatible = True),
                default = [],
                doc = """
                List of additional arguments to pass into the Kotlin compiler.
            """,
            ),
            "friend_paths": jvm_common.friend_paths_attr(),
            "jar_postprocessor": attrs.option(attrs.exec_dep(), default = None),
            "java": attrs.option(attrs.dep(), default = None),
            "java_agents": attrs.list(attrs.source(), default = []),
            "java_version": attrs.option(attrs.string(), default = None),
            "language": attrs.option(attrs.enum(JvmLanguage), default = None),
            "locales_for_binary_resources": attrs.list(attrs.string(), default = []),
            "manifest_entries": attrs.dict(key = attrs.string(), value = attrs.any(), default = {}),
            "manifest_file": attrs.option(attrs.source(), default = None),
            "manifest_skeleton": attrs.option(attrs.source(), default = None),
            "maven_coords": attrs.option(attrs.string(), default = None),
            "preferred_density_for_binary_resources": attrs.option(attrs.string(), default = None),
            "proguard_config": attrs.option(attrs.source(), default = None),
            "provided_deps": attrs.list(attrs.dep(), default = []),
            "provided_deps_query": attrs.option(attrs.query(), default = None),
            "remove_classes": attrs.list(attrs.regex(), default = []),
            "required_for_source_only_abi": attrs.bool(default = False),
            "resource_stable_ids": attrs.option(attrs.source(), default = None),
            "resources": attrs.list(attrs.source(), default = []),
            "resources_root": attrs.option(attrs.string(), default = None),
            "robolectric_runtime_dependencies": attrs.list(attrs.source(), default = []),
            "robolectric_runtime_dependency": attrs.option(
                attrs.source(),
                default = None,
                doc = """
                Robolectric only runs in offline mode with buck. Specify the relative
                 directory containing all the jars Robolectric uses at runtime.
            """,
            ),
            "run_test_separately": attrs.bool(default = False),
            "runtime_deps": attrs.list(attrs.dep(), default = []),
            "source": attrs.option(attrs.string(), default = None),
            "source_only_abi_deps": attrs.list(attrs.dep(), default = []),
            "srcs": attrs.list(attrs.source(), default = []),
            "supports_test_execution_caching": attrs.bool(default = False),
            "target": attrs.option(attrs.string(), default = None),
            "test_case_timeout_ms": attrs.option(attrs.int(), default = None),
            "test_class_names_file": attrs.option(attrs.source(), default = None),
            "test_rule_timeout_ms": attrs.option(attrs.int(), default = None),
            "test_type": attrs.option(attrs.enum(TestType), default = None),
            "unbundled_resources_root": attrs.option(attrs.source(allow_directory = True), default = None),
            "use_cxx_libraries": attrs.option(attrs.bool(), default = None),
            "vm_args": attrs.list(attrs.arg(), default = []),
            "_android_toolchain": toolchains_common.android(),
            "_build_only_native_code": attrs.default_only(attrs.bool(default = is_build_only_native_code())),
            "_exec_os_type": buck.exec_os_type_arg(),
            "_is_building_android_binary": attrs.default_only(attrs.bool(default = False)),
            "_java_test_toolchain": toolchains_common.java_test(),
            "_java_toolchain": toolchains_common.java_for_host_test(),
            "_kotlin_toolchain": toolchains_common.kotlin(),
        }
        | android_common.manifest_arg()
        | android_common.patches_system_module_arg()
        | jvm_common.abi_generation_mode()
        | jvm_common.annotation_processors()
        | jvm_common.k2()
        | jvm_common.incremental()
        | jvm_common.kotlincd_content_based_paths()
        | jvm_common.plugins()
        | jvm_common.kotlin_compiler_plugins()
        | jvm_common.enable_used_classes()
        | jvm_common.classic_java_content_based_paths()
        | re_test_common.test_args()
        | test_common.attributes()
        | buck.licenses_arg()
        | buck.labels_arg()
        | buck.contacts_arg()
    ),
)

android_rules = struct(
    android_aar = android_aar,
    android_app_modularity = android_app_modularity,
    android_binary = android_binary,
    android_build_config = android_build_config,
    android_bundle = android_bundle,
    android_instrumentation_apk = android_instrumentation_apk,
    android_instrumentation_test = android_instrumentation_test,
    android_library = android_library,
    android_manifest = android_manifest,
    android_prebuilt_aar = android_prebuilt_aar,
    android_resource = android_resource,
    apk_genrule = apk_genrule,
    gen_aidl = gen_aidl,
    keystore = keystore,
    prebuilt_native_library = prebuilt_native_library,
    robolectric_test = robolectric_test,
)