bazelbuild / bazelbuild/rules_android

Databinding: Cannot enable strict deps when layout XML references classes from a direct dependency.

Open
#312 1 comment 0 reactions 0 assignees View on GitHub
P2
Dominant language
Java
Stars
203
Forks
95
PR merge metrics
No merged PRs in 30d

Description

### Description of the problem / feature request:

When databinding is enabled, consider

```xml


```

here the class `androidx.constraintlayout.widget.ConstraintLayout` comes from a direct dependency on current module ie. from `@maven//:com_google_android_material_material`.

Even though it is a direct dependency, strict deps check complains that it is a transitive dependency and fails the error

```java
external/remotejdk11_macos/bin/java -XX:+UseParallelOldGC -XX:-CompactStrings '--patch-module=java.compiler=external/remote_java_tools_darwin/java_tools/java_compiler.jar' '--patch-module=jdk.compiler=external/remote_java_tools_darwin/java_tools/jdk_compiler.jar' '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' '--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' '--add-opens=java.base/java.nio=ALL-UNNAMED' '--add-opens=java.base/java.lang=ALL-UNNAMED' -jar external/remote_java_tools_darwin/java_tools/JavaBuilder_deploy.jar @bazel-out/darwin-fastbuild/bin/app/libapp.jar-0.params @bazel-out/darwin-fastbuild/bin/app/libapp.jar-1.params)
Execution platform: @local_config_platform//:host
bazel-out/darwin-fastbuild/bin/app/_javac/app/libapp_sources/com/example/databindingstrictdeps/databinding/ActivityMainBindingImpl.java:20: error: [strict] Using type androidx.constraintlayout.widget.ConstraintLayout from an indirect dependency (TOOL_INFO: "bazel-out/android-armeabi-v7a-fastbuild/bin/external/maven/_aar/androidx_constraintlayout_constraintlayout/classes_and_libs_merged.jar").
private final androidx.constraintlayout.widget.ConstraintLayout mboundView0;
^
Target //app:app failed to build

```

### Feature requests: what underlying problem are you trying to solve with this feature?

```bash
build --strict_java_deps=off
```

fixes the issue but would like to enable strict deps.

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

[databindingstrictdeps.zip](https://github.com/bazelbuild/bazel/files/6762926/databindingstrictdeps.zip)

1. Unzip and run
```bash
bazelisk build //app
```

Observe build failed.

### What operating system are you running Bazel on?

MacOs Catalina 10.15.7

### What's the output of `bazel info release`?

release 4.1.0

### If `bazel info release` returns "development version" or "(@non-git)", tell us how you built Bazel.

NIL

### What's the output of `git remote get-url origin ; git rev-parse master ; git rev-parse HEAD` ?

NIL

### Have you found anything relevant by searching the web?

I suspect this function is the cause: https://github.com/bazelbuild/bazel/blob/13b737acf6ae76539adb76e43a6fddf6d0684691/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java#L868

I think JavaCommon created there does not handle deps correctly considering this function is only used for Databinding it does not affect Bazel's other Java functionality.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.