Rules
- android_binary
- aar_import
- android_library
- android_instrumentation_test
- android_local_test
- android_device
- android_ndk_repository
- android_sdk_repository
android_binary
View rule sourceandroid_binary(name, deps, srcs, assets, assets_dir, compatible_with, crunch_png, custom_package, debug_key, debug_signing_keys, debug_signing_lineage_file, densities, deprecation, dex_shards, dexopts, distribs, enable_data_binding, exec_compatible_with, exec_properties, features, incremental_dexing, instruments, javacopts, key_rotation_min_sdk, licenses, main_dex_list, main_dex_list_opts, main_dex_proguard_specs, manifest, manifest_values, multidex, nocompress_extensions, package_id, plugins, proguard_apply_dictionary, proguard_apply_mapping, proguard_generate_mapping, proguard_specs, resource_configuration_filters, resource_files, restricted_to, shrink_resources, tags, target_compatible_with, testonly, visibility)
Produces Android application package files (.apk).
Implicit output targets
- name.apk: An Android application package file signed with debug keys and zipaligned, it could be used to develop and debug your application. You cannot release your application when signed with the debug keys.
- name_unsigned.apk: An unsigned version of the above file that could be signed with the release keys before release to the public.
- name_deploy.jar: A Java archive containing the transitive closure of this target.- The deploy jar contains all the classes that would be found by a classloader that searched the runtime classpath of this target from beginning to end. 
- name_proguard.jar: A Java archive containing the result of running ProGuard on the- name_deploy.jar. This output is only produced if proguard_specs attribute is specified.
- name_proguard.map: A mapping file result of running ProGuard on the- name_deploy.jar. This output is only produced if proguard_specs attribute is specified and proguard_generate_mapping or shrink_resources is set.
Examples
Examples of Android rules can be found in the examples/android directory of the
Bazel source tree.
  
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| deps | List of labels; default is  android_library,java_librarywithandroidconstraint andcc_librarywrapping or producing.sonative libraries for the
          Android target platform. | 
| srcs | List of labels; default is  
 
 | 
| assets | List of labels; default is  globof all files under theassetsdirectory. You can also reference other rules (any rule that produces
          files) or exported files in the other packages, as long as all those files are under theassets_dirdirectory in the corresponding package. | 
| assets_dir | String; default is  assets.
          The pairassetsandassets_dirdescribe packaged
          assets and either both attributes should be provided or none of them. | 
| crunch_png | Boolean; default is  | 
| custom_package | String; default is  | 
| debug_key | Label; default is  WARNING: Do not use your production keys, they should be strictly safeguarded and not kept in your source tree. | 
| debug_signing_keys | List of labels; default is  WARNING: Do not use your production keys, they should be strictly safeguarded and not kept in your source tree. | 
| debug_signing_lineage_file | Label; default is  WARNING: Do not use your production keys, they should be strictly safeguarded and not kept in your source tree. | 
| densities | List of strings; default is  | 
| dex_shards | Integer; default is  Note that each shard will result in at least one dex in the final app. For this reason, setting this to more than 1 is not recommended for release binaries. | 
| dexopts | List of strings; default is  | 
| enable_data_binding | Boolean; default is  To build an Android app with data binding, you must also do the following: 
 | 
| incremental_dexing | Integer; nonconfigurable; default is  | 
| instruments | Label; default is  The  If this attribute is set, this  | 
| javacopts | List of strings; default is  These compiler options are passed to javac after the global compiler options. | 
| key_rotation_min_sdk | String; default is  | 
| main_dex_list | Label; default is  
          android/support/multidex/MultiDex$V19.class
          android/support/multidex/MultiDex.class
          android/support/multidex/MultiDexApplication.class
          com/google/common/base/Objects.class
                    multidex="manual_main_dex". | 
| main_dex_list_opts | List of strings; default is  | 
| main_dex_proguard_specs | List of labels; default is  multidexattribute is set tolegacy. | 
| manifest | Label; requiredThe name of the Android manifest file, normally AndroidManifest.xml.
          Must be defined if resource_files or assets are defined. | 
| manifest_values | Dictionary: String -> String; default is  
          Any instance of  
           
           
          When  | 
| multidex | String; default is  Possible values: 
 | 
| nocompress_extensions | List of strings; default is  | 
| package_id | Integer; default is  See AAPT2's  | 
| plugins | List of labels; default is  java_pluginspecified in
          the plugins attribute will be run whenever
          this target is built.  Resources generated by
          the plugin will be included in the result jar of
          the target. | 
| proguard_apply_dictionary | Label; default is  | 
| proguard_apply_mapping | Label; default is  proguard_generate_mappingto be
          re-used to apply the same mapping to a new build. | 
| proguard_generate_mapping | Boolean; nonconfigurable; default is  proguard_specsis
          specified. This file will list the mapping between the original and
          obfuscated class, method, and field names.WARNING: If this attribute is used, the Proguard
          specification should contain neither  | 
| proguard_specs | List of labels; default is  | 
| resource_configuration_filters | List of strings; default is  en_XAand/orar_XBpseudo-locales. | 
| resource_files | List of labels; default is  globof all files under theresdirectory.Generated files (from genrules) can be referenced by Label here as well. The only restriction is that the generated outputs must be under the same " res" directory as any other
          resource files that are included. | 
| shrink_resources | Integer; default is  manifestandresource_filesattributes) and requires ProGuard.
          It operates in mostly the same manner as the Gradle resource shrinker
          (https://developer.android.com/studio/build/shrink-code.html#shrink-resources).Notable differences: 
 name_files/resource_shrinker.logwill also be generated, detailing the analysis and deletions performed.Possible values: 
 | 
aar_import
View rule sourceaar_import(name, deps, data, aar, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, exports, features, licenses, restricted_to, srcjar, tags, target_compatible_with, testonly, visibility)
  This rule allows the use of .aar files as libraries for
  android_library and
  android_binary rules.
Examples
    aar_import(
        name = "google-vr-sdk",
        aar = "gvr-android-sdk/libraries/sdk-common-1.10.0.aar",
    )
    android_binary(
        name = "app",
        manifest = "AndroidManifest.xml",
        srcs = glob(["**.java"]),
        deps = [":google-vr-sdk"],
    )
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| aar | Label; requiredThe .aarfile to provide to the Android targets that depend on this target. | 
| exports | List of labels; default is  | 
| srcjar | Label; default is  | 
android_library
View rule sourceandroid_library(name, deps, srcs, data, assets, assets_dir, compatible_with, custom_package, deprecation, distribs, enable_data_binding, exec_compatible_with, exec_properties, exported_plugins, exports, exports_manifest, features, idl_import_root, idl_parcelables, idl_preprocessed, idl_srcs, javacopts, licenses, manifest, neverlink, plugins, proguard_specs, resource_files, restricted_to, tags, target_compatible_with, testonly, visibility)
This rule compiles and archives its sources into a .jar file.
  The Android runtime library android.jar is implicitly put on
  the compilation class path.
Implicit output targets
- libname.jar: A Java archive.
- libname-src.jar: An archive containing the sources ("source jar").
- name.aar: An android 'aar' bundle containing the java archive and resources of this target. It does not contain the transitive closure.
Examples
Examples of Android rules can be found in the examples/android directory of the
Bazel source tree.
The following example shows
how to set idl_import_root.
Let //java/bazel/helloandroid/BUILD contain:
android_library(
    name = "parcelable",
    srcs = ["MyParcelable.java"], # bazel.helloandroid.MyParcelable
    # MyParcelable.aidl will be used as import for other .aidl
    # files that depend on it, but will not be compiled.
    idl_parcelables = ["MyParcelable.aidl"] # bazel.helloandroid.MyParcelable
    # We don't need to specify idl_import_root since the aidl file
    # which declares bazel.helloandroid.MyParcelable
    # is present at java/bazel/helloandroid/MyParcelable.aidl
    # underneath a java root (java/).
)
android_library(
    name = "foreign_parcelable",
    srcs = ["src/android/helloandroid/OtherParcelable.java"], # android.helloandroid.OtherParcelable
    idl_parcelables = [
        "src/android/helloandroid/OtherParcelable.aidl" # android.helloandroid.OtherParcelable
    ],
    # We need to specify idl_import_root because the aidl file which
    # declares android.helloandroid.OtherParcelable is not positioned
    # at android/helloandroid/OtherParcelable.aidl under a normal java root.
    # Setting idl_import_root to "src" in //java/bazel/helloandroid
    # adds java/bazel/helloandroid/src to the list of roots
    # the aidl compiler will search for imported types.
    idl_import_root = "src",
)
# Here, OtherInterface.aidl has an "import android.helloandroid.CallbackInterface;" statement.
android_library(
    name = "foreign_interface",
    idl_srcs = [
        "src/android/helloandroid/OtherInterface.aidl" # android.helloandroid.OtherInterface
        "src/android/helloandroid/CallbackInterface.aidl" # android.helloandroid.CallbackInterface
    ],
    # As above, idl_srcs which are not correctly positioned under a java root
    # must have idl_import_root set. Otherwise, OtherInterface (or any other
    # interface in a library which depends on this one) will not be able
    # to find CallbackInterface when it is imported.
    idl_import_root = "src",
)
# MyParcelable.aidl is imported by MyInterface.aidl, so the generated
# MyInterface.java requires MyParcelable.class at compile time.
# Depending on :parcelable ensures that aidl compilation of MyInterface.aidl
# specifies the correct import roots and can access MyParcelable.aidl, and
# makes MyParcelable.class available to Java compilation of MyInterface.java
# as usual.
android_library(
    name = "idl",
    idl_srcs = ["MyInterface.aidl"],
    deps = [":parcelable"],
)
# Here, ServiceParcelable uses and thus depends on ParcelableService,
# when it's compiled, but ParcelableService also uses ServiceParcelable,
# which creates a circular dependency.
# As a result, these files must be compiled together, in the same android_library.
android_library(
    name = "circular_dependencies",
    srcs = ["ServiceParcelable.java"],
    idl_srcs = ["ParcelableService.aidl"],
    idl_parcelables = ["ServiceParcelable.aidl"],
)
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| deps | List of labels; default is  android_library,java_librarywithandroidconstraint andcc_librarywrapping or producing.sonative libraries
        for the Android target platform. | 
| srcs | List of labels; default is  .javaor.srcjarfiles that
         are processed to create the target.
 
 If  | 
| assets | List of labels; default is  globof all files under theassetsdirectory. You can also reference other rules (any rule that produces
          files) or exported files in the other packages, as long as all those files are under theassets_dirdirectory in the corresponding package. | 
| assets_dir | String; default is  assets.
          The pairassetsandassets_dirdescribe packaged
          assets and either both attributes should be provided or none of them. | 
| custom_package | String; default is  | 
| enable_data_binding | Boolean; default is  To build an Android app with data binding, you must also do the following: 
 | 
| exported_plugins | List of labels; default is  java_plugins (e.g. annotation
        processors) to export to libraries that directly depend on this library.
          The specified list of  | 
| exports | List of labels; default is  exportsattributes
        are considered direct dependencies of any rule that directly depends on the
        target withexports.The  | 
| exports_manifest | Integer; default is  android_binarytargets
        that depend on this target.uses-permissionsattributes are never exported. | 
| idl_import_root | String; default is  This path will be used as the import root when processing idl sources that depend on this library. When  See examples. | 
| idl_parcelables | List of labels; default is  android_librarytarget that depends on this library, directly
        or via its transitive closure, but will not be translated to Java
        or compiled.Only  These files must be placed appropriately for the aidl compiler to find them. See the description of idl_import_root for information about what this means. | 
| idl_preprocessed | List of labels; default is  android_librarytarget that depends on this library, directly
        or via its transitive closure, but will not be translated to Java
        or compiled.Only preprocessed  | 
| idl_srcs | List of labels; default is  srcs.These files will be made available as imports for any
         These files must be placed appropriately for the aidl compiler to find them. See the description of idl_import_root for information about what this means. | 
| javacopts | List of strings; default is  These compiler options are passed to javac after the global compiler options. | 
| manifest | Label; default is  AndroidManifest.xml.
          Must be defined if resource_files or assets are defined. | 
| neverlink | Boolean; default is  neverlinkwill not be used in.apkcreation. Useful if the library will be provided by the
        runtime environment during execution. | 
| plugins | List of labels; default is  java_pluginspecified in
          the plugins attribute will be run whenever
          this target is built.  Resources generated by
          the plugin will be included in the result jar of
          the target. | 
| proguard_specs | List of labels; default is  android_binarytarget depending on this library.
        The files included here must only have idempotent rules, namely -dontnote, -dontwarn,
        assumenosideeffects, and rules that start with -keep. Other options can only appear inandroid_binary's proguard_specs, to ensure non-tautological merges. | 
| resource_files | List of labels; default is  globof all files under theresdirectory.Generated files (from genrules) can be referenced by Label here as well. The only restriction is that the generated outputs must be under the same " res" directory as any other
          resource files that are included. | 
android_instrumentation_test
View rule sourceandroid_instrumentation_test(name, data, args, compatible_with, deprecation, distribs, env, env_inherit, exec_compatible_with, exec_properties, features, flaky, licenses, local, restricted_to, shard_count, size, support_apks, tags, target_compatible_with, target_device, test_app, testonly, timeout, toolchains, visibility)
  An android_instrumentation_test rule runs Android instrumentation tests. It will
  start an emulator, install the application being tested, the test application, and
  any other needed applications, and run the tests defined in the test package.
  The test_app attribute specifies the
  android_binary which contains the test. This android_binary in turn
  specifies the android_binary application under test through its
  instruments attribute.
Example
# java/com/samples/hello_world/BUILD
android_library(
    name = "hello_world_lib",
    srcs = ["Lib.java"],
    manifest = "LibraryManifest.xml",
    resource_files = glob(["res/**"]),
)
# The app under test
android_binary(
    name = "hello_world_app",
    manifest = "AndroidManifest.xml",
    deps = [":hello_world_lib"],
)
# javatests/com/samples/hello_world/BUILD
android_library(
    name = "hello_world_test_lib",
    srcs = ["Tests.java"],
    deps = [
      "//java/com/samples/hello_world:hello_world_lib",
      ...  # test dependencies such as Espresso and Mockito
    ],
)
# The test app
android_binary(
    name = "hello_world_test_app",
    instruments = "//java/com/samples/hello_world:hello_world_app",
    manifest = "AndroidManifest.xml",
    deps = [":hello_world_test_lib"],
)
android_instrumentation_test(
    name = "hello_world_uiinstrumentation_tests",
    target_device = ":some_target_device",
    test_app = ":hello_world_test_app",
)
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| support_apks | List of labels; default is  | 
| target_device | Label; required The android_device the test should run on. To run the test on an emulator that is already running or on a physical device, use
        these arguments:
         | 
| test_app | Label; requiredThe android_binary target containing the test classes. The android_binarytarget must specify which target it is testing through
         itsinstrumentsattribute. | 
android_local_test
View rule sourceandroid_local_test(name, deps, srcs, data, args, compatible_with, custom_package, densities, deprecation, enable_data_binding, env, env_inherit, exec_compatible_with, exec_properties, features, flaky, javacopts, jvm_flags, licenses, local, manifest, manifest_values, nocompress_extensions, plugins, resource_configuration_filters, resource_jars, resource_strip_prefix, restricted_to, runtime_deps, shard_count, size, stamp, tags, target_compatible_with, test_class, testonly, timeout, toolchains, use_launcher, visibility)
This rule is for unit testing android_library rules locally
(as opposed to on a device).
It works with the Android Robolectric testing framework.
See the Android Robolectric site for details about
writing Robolectric tests.
Implicit output targets
- name.jar: A Java archive of the test.
- name-src.jar: An archive containing the sources ("source jar").
- name_deploy.jar: A Java deploy archive suitable for deployment (only built if explicitly requested).
Examples
To use Robolectric with android_local_test, add
Robolectric's
repository to your WORKSPACE file:
http_archive(
    name = "robolectric",
    urls = ["https://github.com/robolectric/robolectric-bazel/archive/<COMMIT>.tar.gz"],
    strip_prefix = "robolectric-bazel-<COMMIT>",
    sha256 = "<HASH>",
)
load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")
robolectric_repositories()
maven_jar rules needed for Robolectric.
Then each android_local_test rule should depend on
@robolectric//bazel:robolectric. See example below.
android_local_test(
    name = "SampleTest",
    srcs = [
        "SampleTest.java",
    ],
    manifest = "LibManifest.xml",
    deps = [
        ":sample_test_lib",
        "@robolectric//bazel:android-all",
    ],
)
android_library(
    name = "sample_test_lib",
    srcs = [
         "Lib.java",
    ],
    resource_files = glob(["res/**"]),
    manifest = "AndroidManifest.xml",
)
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| deps | List of labels; default is  
        The list of allowed rules in  | 
| srcs | List of labels; default is  
 
 All other files are ignored, as long as there is at least one file of a file type described above. Otherwise an error is raised. 
        The  | 
| custom_package | String; default is  test_classas well. | 
| densities | List of strings; default is  | 
| enable_data_binding | Boolean; default is  | 
| javacopts | List of strings; default is  These compiler options are passed to javac after the global compiler options. | 
| jvm_flags | List of strings; default is  The wrapper script for a Java binary includes a CLASSPATH definition
          (to find all the dependent jars) and invokes the right Java interpreter.
          The command line generated by the wrapper script includes the name of
          the main class followed by a  Note that this attribute has no effect on  | 
| manifest | Label; default is  AndroidManifest.xml.
        Must be defined if resource_files or assets are defined or if any of the manifests from
        the libraries under test have aminSdkVersiontag in them. | 
| manifest_values | Dictionary: String -> String; default is  applicationId,versionCode,versionName,minSdkVersion,targetSdkVersionandmaxSdkVersionwill also override the corresponding attributes
        of the manifest and
        uses-sdk tags.packageNamewill be ignored and will be set from eitherapplicationIdif
        specified or the package in the manifest.
        It is not necessary to have a manifest on the rule in order to use manifest_values. | 
| nocompress_extensions | List of strings; default is  | 
| plugins | List of labels; default is  java_pluginspecified in this attribute will be run whenever this rule
          is built. A library may also inherit plugins from dependencies that useexported_plugins. Resources
          generated by the plugin will be included in the resulting jar of this rule. | 
| resource_configuration_filters | List of strings; default is  | 
| resource_jars | List of labels; default is  | 
| resource_strip_prefix | String; default is  
            If specified, this path prefix is stripped from every file in the  | 
| runtime_deps | List of labels; default is  deps, these will appear on the runtime classpath, but unlike
          them, not on the compile-time classpath. Dependencies needed only at runtime should be
          listed here. Dependency-analysis tools should ignore targets that appear in bothruntime_depsanddeps. | 
| stamp | Integer; default is  
 Stamped binaries are not rebuilt unless their dependencies change. | 
| test_class | String; default is  
        This attribute specifies the name of a Java class to be run by
        this test. It is rare to need to set this. If this argument is omitted, the Java class
        whose name corresponds to the  | 
| use_launcher | Boolean; default is  If this attribute is set to false, the
          launcher attribute  and the related
           | 
android_device
View rule sourceandroid_device(name, cache, compatible_with, default_properties, deprecation, distribs, exec_compatible_with, exec_properties, features, horizontal_resolution, licenses, platform_apks, ram, restricted_to, screen_density, system_image, tags, target_compatible_with, testonly, vertical_resolution, visibility, vm_heap)
This rule creates an android emulator configured with the given specifications. This emulator may be started via a bazel run command or by executing the generated script directly. It is encouraged to depend on existing android_device rules rather than defining your own.
This rule is a suitable target for the --run_under flag to bazel test and blaze run. It starts an emulator, copies the target being tested/run to the emulator, and tests it or runs it as appropriate.
android_device supports creating KVM images if the underlying
  system_image is X86 based and is
  optimized for at most the I686 CPU architecture. To use KVM add
   tags = ['requires-kvm']  to the android_device rule.
Implicit output targets
- name_images/userdata.dat: Contains image files and snapshots to start the emulator
- name_images/emulator-meta-data.pb: Contains serialized information necessary to pass on to the emulator to restart it.
Examples
The following example shows how to use android_device.
//java/android/helloandroid/BUILD contains
android_device(
    name = "nexus_s",
    cache = 32,
    default_properties = "nexus_s.properties",
    horizontal_resolution = 480,
    ram = 512,
    screen_density = 233,
    system_image = ":emulator_images_android_16_x86",
    vertical_resolution = 800,
    vm_heap = 32,
)
filegroup(
    name = "emulator_images_android_16_x86",
    srcs = glob(["androidsdk/system-images/android-16/**"]),
)
//java/android/helloandroid/nexus_s.properties contains:
ro.product.brand=google ro.product.device=crespo ro.product.manufacturer=samsung ro.product.model=Nexus S ro.product.name=soju
This rule will generate images and a start script. You can start the emulator locally by executing bazel run :nexus_s -- --action=start. The script exposes the following flags:
- --adb_port: The port to expose adb on. If you wish to issue adb commands to the emulator this is the port you will issue adb connect to.
- --emulator_port: The port to expose the emulator's telnet management console on.
- --enable_display: Starts the emulator with a display if true (defaults to false).
- --action: Either start or kill.
- --apks_to_install: a list of apks to install on the emulator.
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| cache | Integer; requiredThe size in megabytes of the emulator's cache partition. The minimum value of this is 16 megabytes. | 
| default_properties | Label; default is  | 
| horizontal_resolution | Integer; requiredThe horizontal screen resolution in pixels to emulate. The minimum value is 240. | 
| platform_apks | List of labels; default is  | 
| ram | Integer; requiredThe amount of ram in megabytes to emulate for the device. This is for the entire device, not just for a particular app installed on the device. The minimum value is 64 megabytes. | 
| screen_density | Integer; requiredThe density of the emulated screen in pixels per inch. The minimum value of this is 30 ppi. | 
| system_image | Label; requiredA filegroup containing the following files: 
 | 
| vertical_resolution | Integer; requiredThe vertical screen resolution in pixels to emulate. The minimum value is 240. | 
| vm_heap | Integer; requiredThe size in megabytes of the virtual machine heap Android will use for each process. The minimum value is 16 megabytes. | 
android_ndk_repository
View rule sourceandroid_ndk_repository(name, api_level, path, repo_mapping)
Configures Bazel to use an Android NDK to support building Android targets with native code.
Note that this implementation of android_ndk_repository is being replaced by an
implementation in Starlark. Support for future versions of the NDK including version 25 and up will
be implemented in the Starlark version of android_ndk_repository. See
rules_android_ndk for the Starlark
version.
Note that building for Android also requires an android_sdk_repository rule in your
WORKSPACE file.
For more information, read the full documentation on using Android NDK with Bazel.
Examples
android_ndk_repository(
    name = "androidndk",
)
The above example will locate your Android NDK from $ANDROID_NDK_HOME and detect
the highest API level that it supports.
android_ndk_repository(
    name = "androidndk",
    path = "./android-ndk-r20",
    api_level = 24,
)
The above example will use the Android NDK located inside your workspace in
./android-ndk-r20. It will use the API level 24 libraries when compiling your JNI
code.
cpufeatures
The Android NDK contains the cpufeatures library which can be used to detect a device's CPU at runtime. The following example demonstrates how to use cpufeatures with Bazel.
# jni.cc #include "ndk/sources/android/cpufeatures/cpu-features.h" ...
# BUILD
cc_library(
    name = "jni",
    srcs = ["jni.cc"],
    deps = ["@androidndk//:cpufeatures"],
)
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| api_level | Integer; nonconfigurable; default is  | 
| path | String; nonconfigurable; default is  $ANDROID_NDK_HOMEenvironment variable must be set.The Android NDK can be downloaded from the Android developer site . | 
| repo_mapping | Dictionary: String -> String; default is  For example, an entry  | 
android_sdk_repository
View rule sourceandroid_sdk_repository(name, api_level, build_tools_version, path, repo_mapping)
Configures Bazel to use a local Android SDK to support building Android targets.
Examples
The minimum to set up an Android SDK for Bazel is to put anandroid_sdk_repository rule
named "androidsdk" in your WORKSPACE file and set the $ANDROID_HOME
environment variable to the path of your Android SDK. Bazel will use the highest Android API level
and build tools version installed in the Android SDK by default.
android_sdk_repository(
    name = "androidsdk",
)
To ensure reproducible builds, the path, api_level and
build_tools_version attributes can be set to specific values. The build will fail if
the Android SDK does not have the specified API level or build tools version installed.
android_sdk_repository(
    name = "androidsdk",
    path = "./sdk",
    api_level = 19,
    build_tools_version = "25.0.0",
)
The above example also demonstrates using a workspace-relative path to the Android SDK. This is useful if the Android SDK is part of your Bazel workspace (e.g. if it is checked into version control).
Support Libraries
The Support Libraries are available in the Android SDK Manager as "Android Support Repository".
This is a versioned set of common Android libraries, such as the Support and AppCompat libraries,
that is packaged as a local Maven repository. android_sdk_repository generates Bazel
targets for each of these libraries that can be used in the dependencies of
android_binary and android_library targets.
The names of the generated targets are derived from the Maven coordinates of the libraries in the
Android Support Repository, formatted as @androidsdk//${group}:${artifact}-${version}.
The following example shows how an android_library can depend on version 25.0.0 of the
v7 appcompat library.
android_library(
    name = "lib",
    srcs = glob(["*.java"]),
    manifest = "AndroidManifest.xml",
    resource_files = glob(["res/**"]),
    deps = ["@androidsdk//com.android.support:appcompat-v7-25.0.0"],
)
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| api_level | Integer; nonconfigurable; default is  The API level used for a given build can be overridden by the  To view all  | 
| build_tools_version | String; nonconfigurable; default is  Bazel requires build tools version 30.0.0 or later. | 
| path | String; nonconfigurable; default is  $ANDROID_HOMEenvironment variable must be set.The Android SDK can be downloaded from the Android developer site. | 
| repo_mapping | Dictionary: String -> String; default is  For example, an entry  |