在使用kotlin開發的安卓項目中,開啓DataBinding步驟如下:
1.在app的build.gradle的android配置項下添加如下:
dataBinding{
enabled = true
}
2.在app的build.gradle中引入:
apply plugin: 'kotlin-kapt'
3.在dependencies中添加:
kapt 'com.android.databinding:compiler:$version'
4.如果編譯遇到如下報錯:
[kapt] Incremental annotation processing requested, but support is disabled because the following processors are not incremental:
android.databinding.compiler.Processor (NON_INCREMENTAL),
android.databinding.compiler.xxxxx (NON_INCREMENTAL).
請在android配置項下添加
kapt {
generateStubs = true
}