Search code examples
androidkotlingradle-kotlin-dsl

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

  • This is how i enabled dataBinding in kotlin gradle file :

    dataBinding {
        isEnabled = true
    }
    

    Voila ;)

    hope this help someone