I am using data binding in my project, and when using <layout>
and <data>
in the data binding xml class, unfortunately it doesn't work properly.. no files are generated at all. For example I have activity_main.xml.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data> </data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</layout>
Now if I write ActivityMainBinding
in my activity/fragment it shows error that class is not available. But after including <variable>
in my xml file it is able to generate ActivityMainBinding class.
Is there something wrong with my project configuration?
Android Studio : 2.1.3
Classpath : com.android.tools.build:gradle:2.1.3
minSdkVersion 16
targetSdkVersion 24
buildToolsVersion 24.0.0
Solution
I didn't get a satisfactory answer. These are the tips which are a summary of my knowledge about data binding.
Tips to solve data binding related issues, it is better if you update Android Studio and Gradle plugin version to the latest. Because I did not face much issue after AS 3.2 version.
1. Make sure the data-binding configuration is enabled
You must enable data binding in your build.gradle file. If not, add this and Sync.
android {
...
buildFeatures {
dataBinding true
}
}
2. Clean up your project
Clean your project with the clean up project & clear cache menu, then rebuild it again and enjoy working with auto suggestions for calling XML assets via data binding.