'Databinding unresolved after move to Gradle Kotlin DSL build scripts
I had a working build, including databinding, but after migrating my Gradle build scripts to Kotlin DSL, I now have unresolved symbol errors for every use of import androidx.databinding.DataBindingUtil
My build.properties.kts
contains the following:
plugins {
id ("com.android.application")
kotlin ("android")
kotlin ("android.extensions")
id ("de.mannodermaus.android-junit5")
}
android {
lintOptions.isAbortOnError = false
compileSdkVersion(28)
defaultConfig {
// ...
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles (getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
dataBinding.isEnabled = true
sourceSets {
getByName("main").java.srcDir("src/main/kotlin")
getByName("test").java.srcDir("src/test/kotlin")
}
}
dependencies {
// ...
}
Is dataBinding.isEnabled = true
the right way to enable databinding, or do I need to do something else? (I know I could 'fix' this by going back to Groovy, but that feels a bit too much like giving up!)
Solution 1:[1]
This is how i enabled dataBinding in kotlin gradle file :
dataBinding {
isEnabled = true
}
Voila ;)
hope this help someone
Solution 2:[2]
android {
...
buildFeatures {
dataBinding = true
}
...
Solution 3:[3]
and for ViewBinding you can use :
viewBinding.isEnabled = true
Solution 4:[4]
EDIT: in 2019 databinding.isEnabled = true
was the correct way to enable databinding.
Please now refer to the accepted solution for the right way to do this.
The problem turned out to be in my file naming. While migrating to Kotlin DSL, I had inadvertently renamed the gradle.properties
file to gradle.properties.kts
. After renaming the file I now have a fully functional build again!
Solution 5:[5]
You can use it like this:
android {
buildFeatures {
dataBinding = true
// for view binding:
// viewBinding = true
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Michael Lim |
Solution 3 | Sana Ebadi |
Solution 4 | |
Solution 5 | sajad abbasi |