View Bindings not generating
The layout's root tag has to be <layout>
. Make sure it's not your case.
Had to change my original layout XML file
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/welcome_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Hello World!" />
</androidx.constraintlayout.widget.ConstraintLayout>
to
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/welcome_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Hello World!" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
I couldn't find my ViewBinding
files until it dawned on me that the bindings were being named after the XML
files ("fragment_home.xml") and not after the class ("HomeFragment.kt"). So I couldn't find them at HomeFragmentBinding
but I found them at FragmentHomeBinding.
I found it helpful to think of each ViewBinding as a helper singleton that has been created as that XML file's delegate.
(Edited to removed obsolete Gradle stuff)