Status Update
Comments
ya...@gmail.com <ya...@gmail.com> #2
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="
xmlns:app="
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@android:color/transparent"
android:theme="@style/Bain.TextAppearance.Toolbar.Title"
app:titleTextAppearance="@style/TextAppearance.Toolbar.Title" />
vi...@google.com <vi...@google.com>
da...@google.com <da...@google.com> #3
Jake: it says the issue is this is a compile error:
Compile time error:
com.xxxx.databinding:ActivityXXXXBinding.java:34:
error: incompatible types: ToolbarTransparentLayoutBinding cannot be converted to ViewDataBinding
setContainedBinding(this.toolbar);
Why did you move to "android studio > data binding > editing"? Are we suggesting bad autocompletions?
OP: Can you clarify exactly what the problem is? It's not clear to me from a glance. Can you simplify what's happening and what you expect?
ja...@google.com <ja...@google.com> #4
I just moved it to data binding from view binding under the same component hierarchy since it was related to data binding code gen, not view binding.
da...@google.com <da...@google.com> #5
Ah, got it. I'll move it to the AndroidX component. Yigit, please bounce back if this is an IDE issue.
ja...@google.com <ja...@google.com> #6
👍 didn't realize we had jetpack ones
ya...@gmail.com <ya...@gmail.com> #7
Do you need additional information?
da...@google.com <da...@google.com> #8
Yes, sorry -- it might have gotten lost in
OP: Can you clarify exactly what the problem is? It's not clear to me from a glance. Can you simplify what's happening and what you expect?
yb...@google.com <yb...@google.com> #9
Can you provide a sample app that reproduces the issue ? I'm not sure what in the layout is triggering this.
an...@mevotemp.com <an...@mevotemp.com> #10
I encountered the same issue.
- I have both data binding and view binding enabled.
- I have Fragment layout with
<layout>
tag and data binding set up - There is a separate toolbar layout without
<layout>
tag which is included into Fragment layout. (this might be the issue)
My workaround is tools:viewBindingIgnore="true"
for toolbar layout.
Layouts:
Fragment:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="***" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<include
android:id="@+id/toolbarLayout"
layout="@layout/l_toolbar" />
<***>
</LinearLayout>
</layout>
Toolbar:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="@+id/toolbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/rgb_26"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:theme="@style/Toolbar"
app:titleTextAppearance="@style/ToolbarTitleTextStyle" />
</FrameLayout>
an...@mevotemp.com <an...@mevotemp.com> #11
I have created sample app. Rebuild fails every time.
da...@google.com <da...@google.com>
yb...@google.com <yb...@google.com> #12
ok so here data binding is confusing the ViewBinding generated class or a DataBinding one so tries to set a field that does not exist. seems straightforward, i'll work on a test.
yb...@google.com <yb...@google.com> #13
ok this turned to be a lot more complicated than i hoped :(
it is easy to fix the broken code that gets generated but it does not solve the actual problem.
When a data bidning layout includes another binding (view or data), we need to find the binding class generated for it.
For data binding layouts, it relies on DataBindingUtil to get that class :
Since there is no central location to inflate a view binding (similar to DataBindingUtil), there is no easy way to fix this. (nor that i would recommend adding it as it adds significant build complexity).
We need to significantly change how data binding inflates layouts or binds to existing layouts to fix this. We probably also need to ditch the optimization that traverses the layout once (which i wouldn't care much).
Either way, this will be a major change that might also break people if they inadvertently relied on how inflation works in data binding.
My recommendation for now, unfortunately, is to either use ignore or use data binding in that included layout as well.
Jake, any recommendations here that i'm missing ?
A possible workaround might be to make generated binding classes treat view binding includes separately such that it can use findViewById to find them and bind instead of using the 1 pass thing. That would keep it consistent for existing use cases at the cost of complicating our own logic (which i'm fine with).
yb...@google.com <yb...@google.com> #14
i prototyped a solution where the generated Impl considers the view binding layout like a regular view with id for the purposes of construction and call GeneratedViewBinding#bind
after finding views.
It is gross, confusing and some more technical debt but it is probably the best approach to fix this w/o a major change in data binding.
i'll try to cleanup, add more tests and send a CL
Description
AI-192.7142.36.36.6200805, JRE 1.8.0_212-release-1586-b4-5784211x64 JetBrains s.r.o, OS Mac OS X(x86_64) v10.14.6, screens 1280x800; Retina
AS: 3.6; Kotlin plugin: 1.3.61; Android Gradle Plugin: 3.6.0; Gradle: 6.0.1; NDK: from local.properties: 21.0.6113669, latest from SDK: 21.0.6113669; LLDB: pinned revision 3.1 not found, latest from SDK: (package not found); CMake: from local.properties: (not specified), latest from SDK: 3.10.2, from PATH: 3.10.0
IMPORTANT: Please read
generated class:
// Generated by data binding compiler. Do not edit!
package com.xxxx.databinding;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;
import com.xxxx.R;
import java.lang.Deprecated;
import java.lang.Object;
public abstract class ActivityXXXXBinding extends ViewDataBinding {
@NonNull
public final LinearLayout llContainer;
@NonNull
public final RecyclerView rvCountriesCurrencies;
@NonNull
public final ToolbarSmallLayoutBinding toolbar;
protected ActivityXXXXBinding(Object _bindingComponent, View _root,
int _localFieldCount, LinearLayout llContainer, RecyclerView rvCountriesCurrencies,
ToolbarSmallLayoutBinding toolbar) {
super(_bindingComponent, _root, _localFieldCount);
this.llContainer = llContainer;
this.rvCountriesCurrencies = rvCountriesCurrencies;
this.toolbar = toolbar;
setContainedBinding(this.toolbar);
}
@NonNull
public static ActivityXXXXBinding inflate(
@NonNull LayoutInflater inflater, @Nullable ViewGroup root, boolean attachToRoot) {
return inflate(inflater, root, attachToRoot, DataBindingUtil.getDefaultComponent());
}
/**
* This method receives DataBindingComponent instance as type Object instead of
* type DataBindingComponent to avoid causing too many compilation errors if
* compilation fails for another reason.
*
* @Deprecated Use DataBindingUtil.inflate(inflater, R.layout.xxxx_countries_currencies, root, attachToRoot, component)
*/
@NonNull
@Deprecated
public static ActivityXXXXBinding inflate(
@NonNull LayoutInflater inflater, @Nullable ViewGroup root, boolean attachToRoot,
@Nullable Object component) {
return ViewDataBinding.<ActivityXXXXBinding>inflateInternal(inflater, R.layout.activity_xxxx_countries_currencies, root, attachToRoot, component);
}
@NonNull
public static ActivityXXXXBinding inflate(
@NonNull LayoutInflater inflater) {
return inflate(inflater, DataBindingUtil.getDefaultComponent());
}
/**
* This method receives DataBindingComponent instance as type Object instead of
* type DataBindingComponent to avoid causing too many compilation errors if
* compilation fails for another reason.
*
* @Deprecated Use DataBindingUtil.inflate(inflater, R.layout.xxxx_countries_currencies, null, false, component)
*/
@NonNull
@Deprecated
public static ActivityXXXXBinding inflate(
@NonNull LayoutInflater inflater, @Nullable Object component) {
return ViewDataBinding.<ActivityXXXXBinding>inflateInternal(inflater, R.layout.xxxx_countries_currencies, null, false, component);
}
public static ActivityXXXXBinding bind(@NonNull View view) {
return bind(view, DataBindingUtil.getDefaultComponent());
}
/**
* This method receives DataBindingComponent instance as type Object instead of
* type DataBindingComponent to avoid causing too many compilation errors if
* compilation fails for another reason.
*
* @Deprecated Use DataBindingUtil.bind(view, component)
*/
@Deprecated
public static ActivityXXXXBinding bind(@NonNull View view,
@Nullable Object component) {
return (ActivityXXXXBinding)bind(component, view, R.layout.xxxx_countries_currencies);
}
}
Compile time error:
com.xxxx.databinding:ActivityXXXXBinding.java:34:
error: incompatible types: ToolbarTransparentLayoutBinding cannot be converted to ViewDataBinding
setContainedBinding(this.toolbar);