xref: /aosp_15_r20/external/bazelbuild-rules_android/README.md (revision 9e965d6fece27a77de5377433c2f7e6999b8cc0b)
1# Android support in Bazel
2
3## Disclaimer
4
5NOTE: This branch is a development preview of the Starlark implementation of Android rules for Bazel. This code is incomplete and may not function as-is.
6
7A version of Bazel built at or near head or a recent pre-release and the following flags are necessary to use these rules:
8
9```
10--experimental_enable_android_migration_apis
11--experimental_google_legacy_api
12--incompatible_java_common_parameters
13--android_databinding_use_v3_4_args
14--experimental_android_databinding_v2
15```
16
17## Overview
18
19This repository contains the Starlark implementation of Android rules in Bazel.
20
21The rules are being incrementally converted from their native implementations
22in the [Bazel source
23tree](https://source.bazel.build/bazel/+/master:src/main/java/com/google/devtools/build/lib/rules/android/).
24
25For the list of Android rules, see the Bazel [documentation](https://docs.bazel.build/versions/master/be/android.html).
26
27## Getting Started
28To use the Starlark Bazel Android rules, add the following to your WORKSPACE file:
29
30    load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
31
32    # Or a later commit
33    RULES_ANDROID_COMMIT= "0bf3093bd011acd35de3c479c8990dd630d552aa"
34    RULES_ANDROID_SHA = "b75a673a66c157138ab53f4d8612a6e655d38b69bb14207c1a6675f0e10afa61"
35    http_archive(
36        name = "rules_android",
37        url = "https://github.com/bazelbuild/rules_android/archive/%s.zip" % RULES_ANDROID_COMMIT,
38        sha256 = RULES_ANDROID_SHA,
39        strip_prefix = "rules_android-%s" % RULES_ANDROID_COMMIT,
40    )
41    load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
42    rules_android_prereqs()
43    load("@rules_android//:defs.bzl", "rules_android_workspace")
44    rules_android_workspace()
45
46    register_toolchains(
47    "@rules_android//toolchains/android:android_default_toolchain",
48    "@rules_android//toolchains/android_sdk:android_sdk_tools",
49    )
50
51Then, in your BUILD files, import and use the rules:
52
53    load("@rules_android//rules:rules.bzl", "android_binary", "android_library")
54    android_binary(
55        ...
56    )
57
58    android_library(
59        ...
60    )
61