rules_android icon indicating copy to clipboard operation
rules_android copied to clipboard

bzlmod support

Open ted-xie opened this issue 2 years ago • 11 comments

Currently fails with this:

no such target '//external:databinding_annotation_processor': target 'databinding_annotation_processor' not declared in package 'external' defined by <workspace path>/WORKSPACE (Tip: use `query "//external:*"` to see all the targets in that package) and referenced by '@bazel_tools//tools/android:databinding_annotation_processor'

ted-xie avatar Jul 12 '23 21:07 ted-xie

@ahumesky @meisterT

ted-xie avatar Jul 12 '23 21:07 ted-xie

I think that's referenced here: https://github.com/bazelbuild/bazel/blob/d0e29582a2e788e8acdaf53fe30ab7f7dc592df3/tools/android/BUILD.tools#L448

For the starlark rules at least, I think we can point them here instead: https://github.com/bazelbuild/rules_android/blob/a6b9b7921f220f437858b8e19cdd0524923f4f16/tools/android/BUILD#L35

ahumesky avatar Jul 12 '23 21:07 ahumesky

Hm, we appear to already be doing that: https://github.com/bazelbuild/rules_android/blob/a6b9b7921f220f437858b8e19cdd0524923f4f16/toolchains/android/toolchain.bzl#L107

ahumesky avatar Jul 12 '23 21:07 ahumesky

So probably coming from the parts of android_binary that are still in native: https://github.com/bazelbuild/rules_android/blob/a6b9b7921f220f437858b8e19cdd0524923f4f16/rules/android_binary.bzl#L43

ahumesky avatar Jul 12 '23 21:07 ahumesky

But I think we could replace this:

https://github.com/bazelbuild/bazel/blob/d0e29582a2e788e8acdaf53fe30ab7f7dc592df3/tools/android/BUILD.tools#L446-L449

with this: https://github.com/bazelbuild/rules_android/blob/a6b9b7921f220f437858b8e19cdd0524923f4f16/tools/android/BUILD#L34-L42

and change the name to match the existing alias, it should "just work"

ahumesky avatar Jul 12 '23 22:07 ahumesky

Hi folks, quick question - i'm new to bzlmod and trying to setup my android project using bzlmod.

I'm not sure if there's an equivalent to WORKSPACE's android_sdk_repository in bzlmod? When i try to build android_library targets with my MODULE.bazel depending on rules_android module i run into the following error:

While resolving toolchains for target //:sample: No matching toolchains found for types @bazel_tools//tools/android:sdk_toolchain_type.

Wondering if this is related to this issue. i.e. it's not possible yet to setup android projects using bzlmod?

telescopic avatar Aug 21 '23 18:08 telescopic

@telescopic Bzlmod works now but you will need to be using the latest Bazel rolling release until the actual fix get backported into the 6.x release track.

Bencodes avatar Aug 21 '23 20:08 Bencodes

@Bencodes thanks for your reply - is there any documentation surrounding the same?

telescopic avatar Aug 29 '23 06:08 telescopic

@telescopic not much documentation right now.

Bzlmod doesn't actually seem to be fully working if you are using rules_android at HEAD. If you are still using the native rules it's possible to get everything working. Example: https://github.com/robolectric/robolectric-bazel/tree/master/examples/simple

Bencodes avatar Sep 19 '23 23:09 Bencodes

bzlmod support doesn't seem to be working at all: I created a minimal example showing that following the basic instructions on the main README here leads to the repo not being found.

EDIT Huh apparently I had a problem with my bazelrc (failed to include line-continuations), adding those in so the flags were all present I ended up with a different error:

ERROR: no such package '@@android_gmaven_r8//jar': The repository '@@android_gmaven_r8' could not be resolved: Repository '@@android_gmaven_r8' is not defined
ERROR: D:/_bazel_out/lbijidmj/external/androidsdk/BUILD.bazel:31:25: no such package '@@android_gmaven_r8//jar': The repository '@@android_gmaven_r8' could not be resolved: Repository '@@android_gmaven_r8' is not defined and referenced by 
'@@androidsdk//:d8_jar_import'

bdleitner avatar Mar 24 '24 22:03 bdleitner

Hi @bdleitner,

The README is sadly not entirely up to date, especially for bzlmod integration. We will address documentation shortcomings later this year as part of the overall rules maturation process. I have a change in progress that adds the following lines to MODULE.bazel for the example app that should address the issue you're seeing.

remote_android_extensions = use_extension("@bazel_tools//tools/android:android_extensions.bzl", "remote_android_tools_extensions")
use_repo(remote_android_extensions, "android_gmaven_r8", "android_tools")

ted-xie avatar Mar 25 '24 15:03 ted-xie

bzlmod and BCR is now supported with 0.5.0 release

ahumesky avatar Aug 02 '24 19:08 ahumesky