Release summary
We’ve cleaned up legacy Android flags in native Bazel and ported them to rules_android. These changes will take effect in rules_android 0.8.0+ and Bazel 10+.
Android Configuration Flag Starlarkification
We’ve refactored the rule implementations to no longer read from the Bazel Android configuration fragment and instead obtain that information directly from new Starlark flags in rules_android. We’ve added flag_alias()es to rules_android’s MODULE file such that existing uses of relevant Android configuration flags will still work seamlessly.
Android Execution Strategy Flags
The legacy Bazel flags to control Android build execution strategy could not be Starlarkified, and their respective behaviors instead are expressed in the form of many --modify_execution_info flags in android_persistent_workers.bazelrc. We encourage you to copy this file into your project to avoid having to manually specify a large number of execution info flags.
If you relied on e.g. --persistent_android_dex_desugar before, you can activate that behavior with the equivalent --config=persistent_android_dex_desugar after importing the worker bazelrc.
Deprecated Flags
We deprecated around 30 obsolete or no-op native Android flags from Bazel. These should be removed from bazelrc files, scripts, and build invocations in general.
Usage
Using Bzlmod with Bazel 6 or greater
- (Bazel 6 only) Enable with
common --enable_bzlmodin.bazelrc. - Add to your
MODULE.bazelfile:
# See examples/basicapp/MODULE.bazel.
bazel_dep(name = "rules_android", version = "0.8.0")
remote_android_extensions = use_extension(
"@rules_android//bzlmod_extensions:android_extensions.bzl",
"remote_android_tools_extensions")
use_repo(remote_android_extensions, "android_tools")
android_sdk_repository_extension = use_extension("@rules_android//rules/android_sdk_repository:rule.bzl", "android_sdk_repository_extension")
use_repo(android_sdk_repository_extension, "androidsdk")
register_toolchains("@androidsdk//:sdk-toolchain", "@androidsdk//:all")Using WORKSPACE
Paste this snippet into your WORKSPACE.bazel file:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "rules_android",
sha256 = "ebc0b6e0b9461281310fa3038b76d7ed5b5ed929eca3dd15a075dae3664f5cfa",
strip_prefix = "rules_android-0.8.0",
url = "https://github.com/bazelbuild/rules_android/releases/download/v0.8.0/rules_android-v0.8.0.tar.gz",
)
# Android rules dependencies
load("@rules_android//:prereqs.bzl", "rules_android_prereqs")
rules_android_prereqs()
load("@bazel_features//:deps.bzl", "bazel_features_deps")
bazel_features_deps()
load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo")
compatibility_proxy_repo()
##### rules_java setup for rules_android #####
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
rules_java_dependencies()
# note that the following line is what is minimally required from protobuf for the java rules
# consider using the protobuf_deps() public API from @com_google_protobuf//:protobuf_deps.bzl
load("@com_google_protobuf//bazel/private:proto_bazel_features.bzl", "proto_bazel_features") # buildifier: disable=bzl-visibility
proto_bazel_features(name = "proto_bazel_features")
# register toolchains
load("@rules_java//java:repositories.bzl", "rules_java_toolchains")
rules_java_toolchains()
##### rules_jvm_external setup for rules_android #####
load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
rules_jvm_external_deps()
load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
rules_jvm_external_setup()
##### rules_android setup #####
load("@rules_android//:defs.bzl", "rules_android_workspace")
rules_android_workspace()
# Android SDK setup
load("@rules_android//rules:rules.bzl", "android_sdk_repository")
android_sdk_repository(
name = "androidsdk",
)
register_toolchains(
"@rules_android//toolchains/android:android_default_toolchain",
"@rules_android//toolchains/android_sdk:android_sdk_tools",
)In BUILD
Load the rules from rules_android:
load("@rules_android//rules:rules.bzl", "android_binary", "android_library")
android_binary(
...
)
android_library(
...
)