Status Update
Comments
yb...@google.com <yb...@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.
it...@gmail.com <it...@gmail.com> #3
yb...@google.com <yb...@google.com> #4
that seems like a different problem with caching. If you can reproduce it, that would be great.
it...@gmail.com <it...@gmail.com> #5
ga...@linecorp.com <ga...@linecorp.com> #6
Can you add more details on what you are trying to achieve?
Sorry for late reply.
To help my colleagues understand, I've already shared the following snippet:
As I already commented, this is a breaking change, and IMHO, this should be announced on release notes.
yb...@google.com <yb...@google.com> #7
I agree, this should've been covered in the release notes. Apologies.
It is not a breaking change as in API guarantees (we almost never allow that) but it is a breaking undefined behavior change that does require updating release notes.
I was wondering, what is the use case for doing this? I understand it used to work but it is basically passing ViewBinding a totally different view (while there is a 1-1 mapping between layout files and view binding). So it was not intended to work for that case. e.g. in data binding, we update layout files in the pipeline to avoid this but in view binding we don't (has additional cost but data binding needs it for other stuff) which allowed this to happen even though it was not designed for.
Description
Component used: Android Gradle Plugin
Version used: 7.0.0
Devices/Android versions reproduced on: All
Sample Project :https://github.com/ganadist/VersionCodeDemo/tree/viewbinding_agp7_crash
In previous commit (https://github.com/ganadist/VersionCodeDemo/commit/12c1d62568 ), App can be started successfully.
But After applied AGP 7.0 (https://github.com/ganadist/VersionCodeDemo/commit/44de6c05 ), App crashed with following message
It seems this is intended changes via b/177013456 , but there is no announcement on release notes .
Please provide announcement and migration guide for behaviour change which can lead app crash.