Android DataBindingClasses are not updating immediately

Viewed 69

Problem:

I'm working on a project having dataBinding integrated now whenever I create a new layout or add a view to an existing one it just not appear in binding object and I even try rebuilding and cleaning the project but it doesn't work and I have to just restart the project or rename the layout file one or two times to update the BindingClass. It is so annoying and consuming my important time.

Code

build.grade

dataBinding {
    enabled = true
}

layout_file

<?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"
    xmlns:tools="http://schemas.android.com/tools">

    <RelativeLayout
        android:id="@+id/lyt_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View android:id="@+id/old_view_1" .../>
        <View android:id="@+id/old_view_2" .../>    

        <!-- New View -->
        <View android:id="@+id/new_view" .../>
    </RelativeLayout>
</layout>

Activity/Fragment/Place where layout is used

LayoutFileBinding binding = DataBindingUtil.setContentView(this, R.layout.layout_file);
binding.newView  
// here I get error cannot resolve (newView) until i restart project or rename layout file 
1 Answers

Data binding and platform support is still not so mature, I am using data binding from a long time, all the issues related to IDE are resolved but your problem happens most of the times with me too.

The most quick fix for me is

  • File > Close Project
  • Open from recent

This takes almost 5 second. and generates all newly added fields and layouts binding classes.

It is faster than Rebuild or Restart AS.

Related