I have following fragment class written in Java using the new databinding library
import com.example.app.databinding.FragmentDataBdinding;
public class Data
I found new solution, hope it will helps you.
First of all check whether plugin applied:
apply plugin: 'kotlin-kapt'
then
android {
...
...
dataBinding {
enabled = true
}
...
...
}
You might have an error in dependency:
USE
kapt 'com.android.databinding:compiler:3.1.4'
instead of
compile 'com.android.databinding:compiler:3.1.4'
You can visit here for new version
Thank you.
Before you try to use FragmentDetailsBinding you have to make sure you converted the corresponding layout( fragment_details.xml ) to data binding layout by wrapping the whole layout in "" tag parent and move all of xmlns to layout tag then build the project and thats it
Try use this configuration:
In main build.gradle:
buildscript {
ext.kotlin_version = '<kotlin-version>'
ext.android_plugin_version = '2.2.0-alpha4'
dependencies {
classpath "com.android.tools.build:gradle:$android_plugin_version"
//... rest of the content
}
}
App build.gradle:
android {
dataBinding {
enabled = true
}
}
dependencies {
kapt "com.android.databinding:compiler:$android_plugin_version"
}
kapt {
generateStubs = true
}
Try this.Andrid studio 2.0(2.1)
In build.gradle
android{
dataBinding {
enabled = true
}
...
}
dependencies {
kapt 'com.android.databinding:compiler:2.0.0-rc1'
....
}
kapt {
generateStubs = true
}
In my project: buildToolsVersion = "23.0.3"
in top level build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
In my case I only forgot to add in layout file the header:
<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">
....
Add Databinding in android Project using when you have use kotlin language.
Below steps
--First you need to add the below plugin
**apply plugin: 'kotlin-kapt'**
--Second dataBinding enabled true
**dataBinding {
enabled = true
}**
All this point added in app.build.gradle after hit "SYNC NOW"
Lets For example you have edit profile activity then how to define binding variable in kotlin??
lateinit var buildProfileBinding: ActivityBuildProfileBinding
buildProfileBinding = getBinding()
Here,get binding is method to handle which type of binding object
protected <T extends ViewDataBinding> T getBinding() {
return (T) binding;
}