I have following fragment class written in Java using the new databinding library
import com.example.app.databinding.FragmentDataBdinding;
public class Data
To Solve the problem, you have to put
apply plugin: 'kotlin-kapt'
at the top of build.gradle (Module: app), then put this line in dependencies
kapt "com.android.databinding:compiler:[YOUR_ANDROID_PLUGIN_VERSION]"
You can find android plugin version by go to menu
File > Project Structure > Project
Then Sync Again. If you see this warning, ignore it.
3rd-party Gradle plug-ins may be the cause
Configuration data binding in kotlin
build.gradle (folder app)
apply plugin: 'kotlin-kapt'
android {
...
dataBinding {
enabled = true
}
}
dependencies {
// data binding
kapt "com.android.databinding:compiler:3.1.3"
}
Enjoy Kotlin...
The version of Data Binding compiler is same as gradle version in your project build.gradle file:
// at the top of file
apply plugin: 'kotlin-kapt'
android {
dataBinding.enabled = true
}
dependencies {
kapt "com.android.databinding:compiler:3.0.0-beta1"
}
and the gradle version is
classpath 'com.android.tools.build:gradle:3.0.0-beta1'
Here is an example link to complete using of databinding library in kotlin.
https://proandroiddev.com/modern-android-development-with-kotlin-september-2017-part-1-f976483f7bd6
You can see in documentation of Android.
The new compiler in version 3.2 is enabled by default.
So Just Update your Android Studio to V3.2 or newer. and remove all unnecessary config.
build.gradle
.android {
dataBinding {
enabled = true
}
}
It will do all things for you automatically.
Remove databinding.compiler
kapt 'com.android.databinding:compiler:3.0.1'
Remove kapt
kapt {
generateStubs = true
}
build.gradle (Project)
kotlin_version = '1.2.71'
classpath 'com.android.tools.build:gradle:3.2.0'
Use gradle latest version. Use kotlin latest version.
build.gradle (App)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
compileSdkVersion 28
targetSdkVersion 28
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Important Do not just copy and paste config. See this answer for setting up Kotlin version.
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
Add following in you app build.gradle
kapt "com.android.databinding:compiler:$android_plugin_version"
apply plugin: 'kotlin-kapt' // This one at top where plugin belong to
This will do the trick.
$android_plugin_version
is version of com.android.tools.build:gradle
in application build.gradle
Also, add this to your module build.gradle
android {
/// Existing Code
kapt {
generateStubs = true
}
}
In my case, the error was Unresolved reference: RegisterationUserBinding
I just used my layout name fragment_registeration_user
like this FragmentRegisterationUserBinding
and made it in the Databinding layout and the error went away.