androidandroid-databinding

DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'


Gets following warning when building the project

DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'.

I am using Android Studio Canary 6


Solution

  • Starting from Android Gradle Plugin 4.0.0-alpha05 there is a new block called buildFeatures to enable build features.

    So in order to enable databinding with new AGP plugin you have do like following in module (ex: app) level gradle file

    build.gradle ( Groovy DSL )

    // shorter version
    // android.buildFeatures.dataBinding true
    
    
    // longer version
    
    android {
    
        buildFeatures {
    
             dataBinding true
    
             // for view binding:
             // viewBinding true
        }
    }
    

    build.gradle.kts ( Kotlin DSL )

    // shorter version
    // android.buildFeatures.dataBinding = true
    
    
    // longer version
    
    android {
    
      buildFeatures {
    
             dataBinding = true
    
             // for view binding:
             // viewBinding = true
        }
    }
    

    Reference: https://developer.android.com/studio/releases/gradle-plugin#buildFeatures