问题
I am converting my Android application from Java to Kotlin. It is working fine, except when I try to convert a file that is using Android Data Binding Library. In that case, Android Studio complains at compile time about unresolved reference:
Error:(10, 44) Unresolved reference: AdapterHistoriesListBinding
Where AdapterHistoriesListBinding is the name of a file that should be generated by the Data Binding Library. It was working correctly in Java, so I guess it is an issue with Kotlin.
I am using Android Studio 2.0.0-beta6, Android Gradle Plugin 2.0.0-beta6 and Kotlin 1.0. Is there something to do to make the Data Binding Library work with Kotlin?
回答1:
Few steps to setup databinding in your Kotlin project.
Tell
kaptto use databinding compiler in module dependencies:dependencies { kapt 'com.android.databinding:compiler:2.0.0-beta6' }As Shintaro Katafuchi mentioned, you should tell
kaptto generate stubs.kapt { generateStubs = true }
回答2:
Have you tried adding following setting in your build.gradle?
kapt {
generateStubs = true
}
回答3:
I have recenly write Blog for Data Binding android with Kotlin here
Use Classpath
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
Dependency
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
...
dataBinding {
enabled = true
}
}
dependencies {
......
kapt 'com.android.databinding:compiler:2.3.1'
}
for more detail check out this post
来源:https://stackoverflow.com/questions/35814837/android-data-binding-and-kotlin