在app build.gradle中添加如下代碼
kapt {
generateStubs = true
}
dependencies {
//...
kapt "com.android.databinding:compiler:2.3.0"
}
kotlin和databinding的完整配置如下
project的build.gradle
buildscript {
ext.kotlin_version = '1.1.0'
ext.android_plugin_version = '2.3.0'
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
//classpath "com.android.tools.build:gradle:$android_plugin_version"
}
}
app的build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
//...
dataBinding {
enabled true
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
kapt {
generateStubs = true
}
dependencies {
//...
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
kapt "com.android.databinding:compiler:$android_plugin_version"
}