Support rules_kotlin's `kt_android_library` in aspect traversal
Maintainers usually reply within 6 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 74/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Domain
- build-system
Research direction
Read _ATTR_ASPECTS in rules/dex_desugar_aspect.bzl and _aspect_attrs in mobile_install/adapters/default.bzl, then reproduce the kt_android_library associates case described in the issue with bazel mobile-install. Done means both aspect traversal lists visit associate targets so their jars and dex shards are included without affecting rules that lack the attribute.
Written by the indexing model from the issue text.
Description
Problem
Several aspects in rules_android have hardcoded attribute traversal lists that predate rules_kotlin's kt_android_library rule. They do not traverse associates, a rules_kotlin-specific attribute that serves as the sole dependency edge for Kotlin internal visibility across targets.
This causes two failures:
-
dex_desugar_aspect: Jars from associate targets are never dexed, producing "Dependencies on .jar artifacts are not allowed in Android binaries" errors. -
mobile-install default adapter: Associate targets' dex shards are absent from the deployed APK, causing
NoClassDefFoundErrorat runtime.
Both work fine with bazel build — only aspect-driven processing is affected.
Background
For Kotlin Android targets, the conventional approach has been the "sandwich" pattern: a kt_jvm_library for Kotlin compilation wrapped by an android_library for Android resource merging. In this pattern, all targets are connected through deps, so aspects can discover them.
In https://github.com/bazel-contrib/rules_kotlin/pull/1333 kt_android_library collapses the sandwich into a single rule. As projects migrate to it, the dependency graph topology changes. Kotlin internal visibility across targets uses the associates attribute (implementing Kotlin's -Xfriend-paths), and associates is often the only edge connecting an implementation target to its wiring/DI target:
# impl/BUILD.bazel
kt_android_library(
name = "impl",
srcs = ["FooImpl.kt"], # contains: internal class FooImpl
)
# wiring/BUILD.bazel
kt_android_library(
name = "wiring",
associates = ["//path/to/impl"], # sole edge to impl
deps = [...],
)
While associate targets' JavaInfo is included in the deps field of the wiring target's JavaInfo provider (so their jars appear in transitive_runtime_jars for the final binary), the aspects need to visit each target individually to dex its jar. Since associates is not in the aspect traversal lists, the associate target is never visited.
Additionally, kt_android_library doesn't have a dedicated mobile-install adapter (unlike android_library and java_library). It falls through to the default adapter, which works but means any future kt_android_library-specific attributes would also be missed.
Affected aspects
| Aspect | File | Missing attribute |
|---|---|---|
dex_desugar_aspect |
rules/dex_desugar_aspect.bzl (_ATTR_ASPECTS) |
associates |
| mobile-install | mobile_install/adapters/default.bzl (_aspect_attrs) |
associates |
Adding an attribute to an aspect's traversal list that doesn't exist on a given rule is safe — Bazel silently skips it.
Reproduction
- Create
kt_android_librarytarget A with aninternal class - Create
kt_android_librarytarget B withassociates = [A](A not indeps) - B instantiates A's internal class (e.g. via Dagger
@Provides) bazel build //appsucceedsbazel mobile-install //appcrashes withNoClassDefFoundError
Environment
- rules_android 0.7.1
- rules_kotlin 2.1.8
- Bazel 8.6
- Dominant language
- Java
- Stars
- 205
- Forks
- 113
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bazelbuild/rules_android
-
build_java8_legacy_dex.sh does not set JAVA_RUNFILES for the d8/r8 launchersPossibly taken @TrapsterDK claimed this 17 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 72/100
bazelbuild/rules_android#599 ·
Maintainers usually reply within 6 days
-
`Desugar` actions don't run on multiplex workersPossibly taken @lukaciko claimed this 46 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bazelbuild/rules_android#539 · 2 comments ·
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
bazelbuild/rules_android#535 · 2 reactions ·
Maintainers usually reply within 6 days
-
desugar_globals output is not reproducible (zip entry order varies)Possibly taken @TrapsterDK claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 30/100
bazelbuild/rules_android#610 ·
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 42/100
bazelbuild/rules_android#602 ·
Maintainers usually reply within 6 days
All issues in bazelbuild/rules_android
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Lincoln-cn/JAiRouter#1473 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
exercism/java-analyzer#379 ·
-
area: ui bug priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
tetsuji16/microProject#1893 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
liberation-data/fornax4j#325 ·
Maintainers usually reply within 1 day
-
[Bug]: FE and Kinesis extraction pipes render flow starting at the centre and scroll the source arm backwardsPossibly taken @chonkzillaofficial claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
BCCE-team/BuildCraft#85 ·