Support rules_kotlin's `kt_android_library` in aspect traversal

オープン
#506 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
android, kotlin
領域
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:

  1. dex_desugar_aspect: Jars from associate targets are never dexed, producing "Dependencies on .jar artifacts are not allowed in Android binaries" errors.

  2. mobile-install default adapter: Associate targets' dex shards are absent from the deployed APK, causing NoClassDefFoundError at 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

  1. Create kt_android_library target A with an internal class
  2. Create kt_android_library target B with associates = [A] (A not in deps)
  3. B instantiates A's internal class (e.g. via Dagger @Provides)
  4. bazel build //app succeeds
  5. bazel mobile-install //app crashes with NoClassDefFoundError

Environment

  • rules_android 0.7.1
  • rules_kotlin 2.1.8
  • Bazel 8.6
主要言語
Java
スター
205
フォーク
113
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bazelbuild/rules_android のほかの issue

bazelbuild/rules_android の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。