Kotlin-android: unresolved reference databinding

后端 未结 16 925
借酒劲吻你
借酒劲吻你 2020-12-02 16:23

I have following fragment class written in Java using the new databinding library

import com.example.app.databinding.FragmentDataBdinding;

public class Data         


        
相关标签:
16条回答
  • 2020-12-02 17:00

    In my case, adding

    kapt {
        generateStubs = true
    }
    

    Solved the problem for me. I ignored it the first time, I thought it's irrelevant to the problem:

    Unresolved reference databinding

    But now, data-binding is working just fine.

    0 讨论(0)
  • 2020-12-02 17:03

    this work for me in androidStudio ver3.1.3

    apply plugin: 'kotlin-kapt'
    
    dataBinding {
        enabled = true
    }
    

    show usage sample

    0 讨论(0)
  • 2020-12-02 17:04

    Update 2: This is a really old answer, instead refer to lrampazzo's answer.

    It works with 1.0-rc4, put

    kapt 'com.android.databinding:compiler:1.0-rc4' 
    

    into your dependencies

    Thanks Ghedeon, for the link in comments

    Update: Here's a really simple hello world example project

    0 讨论(0)
  • 2020-12-02 17:05

    I want to share my own expirience. To use data databinding with Kotlin in android studio is enough to add

    dataBinding {
        enabled = true
    }
    

    After that "sync it" and, it's very important, to "make Project". After that all your object will be active to use.

    0 讨论(0)
提交回复
热议问题