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