简体   繁体   中英

Android Studio Kotlin databinding: Unresolved reference on BR

I have some code that is generating a "red squiggly" error in Android Studio:

@get:Bindable
var title: String = ""
    set(value) {
        field = value
        notifyPropertyChanged(BR.title)
    }

It complains that "title" is an unresolved reference on BR.title . Building and running works fine though, and this is the only error I can see. I debug there and see that it's gotten the value for BR.title correctly.

Still, I can't figure out how to make it go away. I verified that the generated BR class has the "title" field, but Android Studio refuses to recognize this. I've looked up people having this issue and have tried the following: (unsuccessfully)

  • Closing Android Studio, deleting the .gradle, .idea and build folders and restarting
  • Build -> Clean Project, Rebuild Project
  • File -> Invalidate Caches and restart
  • Disabling and enabling the Kotlin plugin
  • Closing and reopening the project

I have also checked and I have apply plugin: 'kotlin-kapt' in build.gradle.

Anyone know what's going on? I assume it must be holding onto some cache files somewhere but I don't know where.

What fixed the problem for me was adding the following import to my files:

import androidx.databinding.library.baseAdapters.BR

I'm not entirely certain why this works, but it got rid of all the analysis problems and the application still compiles and works fine, so I'm personally happy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM