Support rules_kotlin's `kt_android_library` in aspect traversal
维护者通常 6 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 74/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 领域
- build-system
调研方向
阅读 rules/dex_desugar_aspect.bzl 中的 _ATTR_ASPECTS 和 mobile_install/adapters/default.bzl 中的 _aspect_attrs,然后使用 bazel mobile-install 重现 issue 中描述的 kt_android_library associates 案例。完成标准是两个 aspect 遍历列表都会访问 associate 目标,从而包含它们的 jar 和 dex 分片,同时不影响缺少该属性的规则。
由索引模型根据 Issue 内容生成。
描述
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
- 主要语言
- Java
- 星标
- 205
- 派生
- 113
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bazelbuild/rules_android 的其他 Issue
-
build_java8_legacy_dex.sh does not set JAVA_RUNFILES for the d8/r8 launchers可能已有人在做 @TrapsterDK 于 17 天前认领。 未关闭
难度 1/5 1 小时以内 新手友好度 72/100
bazelbuild/rules_android#599 ·
维护者通常 6 天内回复
-
`Desugar` actions don't run on multiplex workers可能已有人在做 @lukaciko 于 46 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
bazelbuild/rules_android#539 · 2 条评论 ·
维护者通常 6 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
bazelbuild/rules_android#535 · 2 个 reaction ·
维护者通常 6 天内回复
-
desugar_globals output is not reproducible (zip entry order varies)可能已有人在做 @TrapsterDK 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 30/100
bazelbuild/rules_android#610 ·
维护者通常 6 天内回复
-
难度 2/5 1-3 小时 新手友好度 42/100
bazelbuild/rules_android#602 ·
维护者通常 6 天内回复
查看 bazelbuild/rules_android 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
Lincoln-cn/JAiRouter#1473 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
exercism/java-analyzer#379 ·
-
area: ui bug priority: low
难度 2/5 1-3 小时 新手友好度 66/100
tetsuji16/microProject#1893 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
liberation-data/fornax4j#325 ·
维护者通常 1 天内回复
-
[Bug]: FE and Kinesis extraction pipes render flow starting at the centre and scroll the source arm backwards可能已有人在做 @chonkzillaofficial 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 79/100
BCCE-team/BuildCraft#85 ·