Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arunkumar9t2 opened this issue Jul 5, 2021 · 1 comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team type: bug

Comments

@arunkumar9t2
Copy link
Contributor

Description of the problem / feature request:

When databinding is enabled, consider

<?xml version="1.0" encoding="utf-8"?>
<layout>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

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

  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?

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

  1. Unzip and run
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:

static JavaCommon createJavaCommonWithAndroidDataBinding(

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.

@arunkumar9t2
Copy link
Contributor Author

Related #2694

@ahumesky ahumesky added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Android Issues for Android team type: bug
Projects
None yet
Development

No branches or pull requests

3 participants