While using data binding , I am not able to get class MainActivityBinding
as per Data Binding Guide
My layout name is activity_main.xml
.
I
In my case: Solve problem without renaming XML file.
I checked all case and I did everything like Invalidate Caches/Restart Android Studio, clean Project, Rebuild Project but But the error is not resolved.
Solution - Just I change some code and revert that code again in activity XML file or change code in XML file.
Note - This is very late answer but may be help others who don't want change XML file name. :)
Please put this code in build.gradle(app level), if not declared.
android {
dataBinding.enabled true
viewBinding {
enabled = true
}
}
// Android Studio 4.0
android {
dataBinding.enabled true
buildFeatures {
viewBinding = true
}
}
Make sure your activity_main.xml file is enclosed with layout tags like so:
<?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">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.constraint.ConstraintLayout>
</layout>
TRY Renaming the xml file to another name and check if binding works once it works rename it back to the one that was used.
That helped for Android Studio 3.1
I recently installed android studio 3.5.3 and this issue rised so what i did is.
1) Clean Project
2) Update Gradle (as notification was coming)
3) Rebuild project
hope this helps.
Cant comment so i'll just add this in answer. I believe activity_main.xml will create ActivityMainBinding rather than MainActivityBinding as you mentioned. in some cases where studio can't find the binding class then just invalidate the caches and rebuild the project.