• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Android support in Bazel
2
3## Disclaimer
4
5NOTE: This branch contains 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 and the following flags are necessary to use these rules:
8```
9--experimental_enable_android_migration_apis
10--experimental_google_legacy_api
11--incompatible_java_common_parameters
12--android_databinding_use_v3_4_args
13--experimental_android_databinding_v2
14```
15
16## Overview
17
18This repository contains the Starlark implementation of Android rules in Bazel.
19
20The rules are being incrementally converted from their native implementations
21in the [Bazel source
22tree](https://source.bazel.build/bazel/+/master:src/main/java/com/google/devtools/build/lib/rules/android/).
23
24For the list of Android rules, see the Bazel [documentation](https://docs.bazel.build/versions/master/be/android.html).
25
26## Getting Started
27To use the new Bazel Android rules, add the following to your WORKSPACE file:
28
29    load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
30    http_archive(
31        name = "build_bazel_rules_android",
32        urls = ["https://github.com/bazelbuild/rules_android/archive/refs/heads/pre-alpha.zip"],
33        strip_prefix = "rules_android-pre-alpha",
34    )
35    load("@build_bazel_rules_android//:defs.bzl", "rules_android_workspace")
36    rules_android_workspace()
37
38    register_toolchains(
39      "@build_bazel_rules_android//toolchains/android:android_default_toolchain",
40      "@build_bazel_rules_android//toolchains/android_sdk:android_sdk_tools",
41    )
42
43
44Then, in your BUILD files, import and use the rules:
45
46    load("@build_bazel_rules_android//rules:rules.bzl", "android_library")
47    android_library(
48        ...
49    )
50