'androidx.databinding.ViewDataBinding.IncludedLayouts has protected access in ViewDataBinding

It was a working project in Android Studio, and today when I opened project it is showing below error for multiple BindingImpl classes. There are two types of error for every BindingImpl class.

The 1st one:

error: cannot find symbol
public class ActivityMainBindingImpl extends ActivityMainBinding  {
                                             ^
  symbol: class ActivityMainBinding

The 2nd one:

error: IncludedLayouts has protected access in ViewDataBinding
    private static final androidx.databinding.ViewDataBinding.IncludedLayouts sIncludes;
                                                             ^

another error in last:

Execution failed for task ':app:kaptProdDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
   > java.lang.reflect.InvocationTargetException (no error message)

What I have tried:

Clean & Rebuild

Invalidate Cache & Restart



Solution 1:[1]

The root view of the layout that you're including must have an id.

Solution 2:[2]

To expand on @zOqvxf's answer:

The layout that you are binding should have a root tag <layout>. You need to add an id to it, like this:

<layout
    ...
    android:id="@+id/layout_root">

Solution 3:[3]

If you have more than one layout file then you have to update both layouts with a layout tag

Ex: activity_main.xml, activity_main.xml land

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zOqvxf
Solution 2 Vas
Solution 3 Rohit Kumar