Android Data Binding and Kotlin
Asked Answered
M

2

17

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?

Mcclary answered 5/3, 2016 at 13:38 Comment(0)
I
20

Few steps to setup databinding in your Kotlin project.

  1. Tell kapt to use databinding compiler in module dependencies:

    dependencies {
      kapt 'com.android.databinding:compiler:2.0.0-beta6'
    }
    
  2. As Shintaro Katafuchi mentioned, you should tell kapt to generate stubs.

    kapt {
      generateStubs = true
    }
    
Ianiana answered 24/3, 2016 at 8:20 Comment(0)
T
2

Have you tried adding following setting in your build.gradle?

kapt {
    generateStubs = true
}
Tapster answered 5/3, 2016 at 18:49 Comment(1)
I just tried adding that in my module's build.gradle (outside the android block), cleaned my project, but the result is the same.Erma

© 2022 - 2024 — McMap. All rights reserved.