Home » Android » android – databinding must include a layout file

android – databinding must include a layout file

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have following very simple layout and wanted to switch to using data binding. Now I’m getting following error in my controller_main.xml:

Error:Execution failed for task ':app:dataBindingProcessLayoutsDebug_pro'.

****/ data binding error ****msg:[44 68 44 68 25] must include a layout
file:…\app\src\main\res\layout\controller_main.xml
****\ data binding error ****

Any ideas? The error says, the resource android:layout id in the include tag is missing (that’s my interpretation of the error), but that’s not true. Commenting out the include tag removes the error.

Does anyone see the problem?

controller_main.xml

<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto" >

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinatorLayout"
        android:fitsSystemWindows="true"
        android:background="?attr/main_background_color"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <RelativeLayout
            android:id="@+id/rlContent"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </RelativeLayout>

        <include
            android:layout_width="fill_parent"
            android:layout_height="@dimen/tool_bar_top_padding"
            android:id="@+id/stub_view_main_header_fixed"
            android:layout="@layout/view_main_header_fixed"
            app:elevation="0dp"/>

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

        </android.support.design.widget.AppBarLayout>

    </android.support.design.widget.CoordinatorLayout>

</layout>

view_main_header_fixed.xml

<?xml version="1.0" encoding="utf-8"?>
<View
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/vStatusbarBackground"
    android:layout_width="match_parent"
    android:layout_height="@dimen/tool_bar_top_padding" />
How to&Answers:

You should use layout instead of android:layout:

<include
        android:layout_width="fill_parent"
        android:layout_height="@dimen/tool_bar_top_padding"
        android:id="@+id/stub_view_main_header_fixed"
        layout="@layout/view_main_header_fixed"
        app:elevation="0dp"/>

Answer:

I had the exact same error, but for a different reason.
I was using <include> opening tag and </include> closing tag instead of <include for opening and /> for closing. It’s little strange, but anyway your question helped me find my mistake. Thanks.