首页 > 解决方案 > How to enable viewBinging in android project using Kotlin gradle dsl?

问题描述

android { ...I'm trying to enalbe ViewBinding in my project witch use Kotlin Gradle DSL. All examples show how to do it with Groovy DSL.

android {
    ...
    viewBinding {
        enabled = true
    }
}

But this solution isn't works with Kotlin DSL. I was trying solution like this:

android {
    ...
    viewBinding.enabled = true
}

But it also doesn't work. It's interesting, that this approach works for DataBinding.

标签: androidkotlingradleandroid-gradle-plugingradle-kotlin-dsl

解决方案


只是做同样事情的一种更新方式,因为isEnabled已被弃用

只需添加此块

 viewBinding {
    android.buildFeatures.viewBinding = true
}

推荐阅读