`dex_desugar_aspect` fails to traverse proto runtime deps under `--incompatible_enable_proto_toolchain_resolution`

Aperta
#497 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
java
Ambito
build-system

Direzione di ricerca

Riproduci il fallimento con il comando Bazel fornito e una dipendenza proto_library/java_lite_proto_library. Leggi _ATTR_ASPECTS in rules/dex_desugar_aspect.bzl e _to_dexed_classpath in rules/dex.bzl, concentrandoti sui jar di runtime risolti tramite toolchain. Il lavoro è completato quando android_binary viene analizzato e compilato con --incompatible_enable_proto_toolchain_resolution senza il fallimento dovuto al jar mancante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

Any android_binary with a transitive dependency on java_lite_proto_library fails at analysis time when --incompatible_enable_proto_toolchain_resolution is enabled (the Bazel 9 default):

Error in fail: Dependencies on .jar artifacts are not allowed in Android binaries, 
please use a java_import to depend on ../protobuf+/java/core/liblite.jar. 
If this is an implicit dependency then the rule that introduces it will need to be fixed to account for it correctly.
Root Cause

dex_desugar_aspect traverses dependencies via the attributes listed in _ATTR_ASPECTS (rules/dex_desugar_aspect.bzl). This list includes _aspect_proto_toolchain_for_javalite and _proto_toolchain_for_javalite, which are the legacy (pre-toolchain-resolution) attributes that java_lite_proto_library used to wire in the proto runtime.

With --incompatible_enable_proto_toolchain_resolution, proto runtime dependencies are resolved via Bazel's toolchain mechanism (@protobuf//bazel/private:javalite_toolchain_type) instead of those explicit rule attributes. The runtime jar (@protobuf//java/core:lite → liblite.jar) is still added to JavaInfo.transitive_runtime_jars by java_lite_proto_library, so it appears on the classpath. But because the dex_desugar_aspect never traversed it, the jar is absent from dex_archives_dict.

In _to_dexed_classpath (rules/dex.bzl), any classpath jar missing from both dex_archives_dict and runtime_jars_dict triggers a fail().

How to Reproduce
  1. Create a proto_library + java_lite_proto_library target
  2. Depend on it (transitively or directly) from an android_binary
  3. Build with --incompatible_enable_proto_toolchain_resolution (Bazel 9 default)
bazel build --incompatible_enable_proto_toolchain_resolution //my:android_app
Environment
  • Bazel 9.1.0
  • protobuf 33.4
  • rules_android 0.7.2
Expected Behavior

The dex_desugar_aspect should handle proto runtime jars resolved via toolchain resolution the same way it handles those discovered through legacy rule attributes.

Workaround

Setting --noincompatible_enable_proto_toolchain_resolution restores the legacy behavior, but this flag is deprecated in Bazel 9.

Lingua principale
Java
Stelle
205
Fork
113
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bazelbuild/rules_android

Tutte le issue di bazelbuild/rules_android

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.