This is to reproduce a problem occurring when using rules_android and a maven repository via rules_jvm_external.
The issue is that, when using certain androidx
Maven repositories, attempting to use the repository as a dependency results in the following error:
$ bazel build //src/main/java/com/example/bazel:greeter_activity --toolchain_resolution_debug='@bazel_tools//tools/android:sdk_toolchain_type'
WARNING: Build option --toolchain_resolution_debug has changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
INFO: ToolchainResolution: Performing resolution of @@bazel_tools//tools/android:sdk_toolchain_type for target platform @@platforms//host:host
ToolchainResolution: No @@bazel_tools//tools/android:sdk_toolchain_type toolchain found for target platform @@platforms//host:host.
ERROR: .../external/rules_jvm_external~~maven~my_maven/BUILD:161:11: While resolving toolchains for target @@rules_jvm_external~~maven~my_maven//:androidx_appcompat_appcompat (1bfa2c2): No matching toolchains found for types @@bazel_tools//tools/android:sdk_toolchain_type.
Ongoing Slack Thread: https://bazelbuild.slack.com/archives/CD9FZL3KR/p1730468977831409
- Check out this repository
- Ensure your
ANDROID_HOME
environment variable is set appropriately. - Execute:
bazel build //src/main/java/com/example/bazel:greeter_activity
The following items have had no effect on fixing the build:
- Including the following in .bazelrc:
common --android_sdk=@androidsdk//:sdk
- Including the following in MODULE.bazel:
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")
Including the following line in WORKSPACE.bzlmod made it work:
android_sdk_repository(name = "androidsdk")
- This has been attempted on an M1 Macbook Pro running Sonoma 14.7.
- The Android App was lifted from the Bazel Android Tutorial example.