7

I am using view binding and to do so I used the following code.

buildFeatures{ viewBinding true }

And I got this error:

> [databinding] {"msg":"Found \u003clayout\u003e but data binding is not
> enabled.\n\nAdd buildFeatures.dataBinding \u003d true to your
> build.gradle to enable
> it.","file":"C:\\Users\\akash\\AndroidStudioProjects\\NavigationSafeArgs\\app\\src\\main\\res\\layout\\fragment_home.xml","pos":[]}

After reading the thrown error I thought It is saying to enable dataBinding So I added dataBinding true too inside buildFeatures. Still It throws the same error.

Here is my fragment_home.xml code;

<?xml version="1.0" encoding="utf-8"?>
<layout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".HomeFragment">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:text="@string/home_screen"
        android:textAppearance="@style/TextAppearance.AppCompat.Large" />

    <Button
        android:id="@+id/button_login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/login" />
</LinearLayout>
</layout>

   
Akr
  • 117
  • 2
  • 10

2 Answers2

28

Enabling dataBinding and viewBinding together solved my problem.

 buildFeatures {
        viewBinding true
        dataBinding true
 }

I also added kotlin-kapt into plugins

plugins {
     id 'kotlin-kapt'
}
Emirhan Soylu
  • 681
  • 6
  • 12
4

I faced the same problem. removing the tags <layout> and </layout> worked for me

Ahmed
  • 51
  • 2