Fixed
Status Update
Comments
cl...@google.com <cl...@google.com> #2
Not sure why this code is doing:
val child2binding = ChildInsideBinding.bind(inside.findViewById(R.id.inside_child))
instead of
val child2binding = ChildInsideBinding.bind(inside)
inside.findViewById(R.id.inside_child)
returns
<LinearLayout
android:id="@+id/inside_child"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text = "I'm child"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
but the binding expects:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/inside_child"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text = "I'm child"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
We needed to make
I'm guessing this code val child2binding = ChildInsideBinding.bind(inside.findViewById(R.id.inside_child))
is like that for the purposes of repro. Can you add more details on what you are trying to achieve?
ViewBinding is generated per layout hierarchy when it happens to work w/ a different layout, it is more of a luck (unreliable) than desired behavior.
ag...@google.com <ag...@google.com>
le...@google.com <le...@google.com> #3
I'm getting similar issues after upgrading to Gradle 7.0. It seems like one out of every 3-4 times I run my project, as soon as the app is launched on my emulator it crashes with a NullPointerException, because it's looking for a seemingly random view that's completely unrelated to the launcher screen of the app. Rebuilding the project and re-launching fixes the issue, but it takes 4-5 minutes to do this each time.
Description
To reproduce, try to compile the following code:
The compilation will fail with an exception like this:
The code compiles successfully with any of the following modifications: