databinding does not exist: How to solve it?

前端 未结 8 955
生来不讨喜
生来不讨喜 2021-01-01 20:37

I\'m working on an Android application with databinding but I\'ve always next error:

Error: Package my.package.databinding

相关标签:
8条回答
  • 2021-01-01 21:12

    This problem occurs usually if your project does not compile. Android databinding should generate code in the named package, but it can't do that if the project doesn't compile in the first place.

    To solve this, bring your project to a point where it compiles. If necessary, turn databinding off for this.

    0 讨论(0)
  • 2021-01-01 21:13

    Based on similar issues on SO, the reasons may not be related to android data binding, and instead due to incorrectly calling variables as in this issue or some other factors like in this other issue. You should provide more details if none of these links helps.

    0 讨论(0)
  • 2021-01-01 21:16

    check out your xml files and comment any @{} you have used unless you actually have your data ready at hand. With no data, you'll bump into this error again and again and again.

    0 讨论(0)
  • 2021-01-01 21:18

    I came across this issue in a project of 4 modules in Android Studio 2.3, it is what @F43nd1r indicated, but want to document what I did to resolve this in my case.

    One of the 4 modules had an older Android Support library in in the Gradle file for it, while the other 3 were current. This is what prevented the project from compiling properly and causing the databinding error.

    The difficult part was that you don't know about this unless you open each build.gradle file and see if there is an error displayed. It did NOT show an error for it on compile.

    Effectively I updated this area to the newer version number to match the other 3 module build.gradle files.

    dependencies {
        ...
        compile 'com.android.support:appcompat-v7:25.2.0'
        compile 'com.android.support:support-v4:25.2.0'
        compile 'com.android.support:recyclerview-v7:25.2.0'
        compile 'com.android.support:design:25.2.0'
        ...
    }
    
    0 讨论(0)
  • 2021-01-01 21:28

    For me doesn't work anything except one: Renamed XML binding class What I tried before: off/on viewBinding renaming folders reinstalling modules renaming modules

    0 讨论(0)
  • 2021-01-01 21:36

    To see the error, just edit these lines of code in the app's build.gradle:

    dataBinding {
    enabled = false
    } 
    

    In this way, the last error in your build console is the actual error. Because from the first to the penultimate error, they are all related to the non-generation of the data binding classes, precisely because we have disabled it.

    Once you find the error you will enter again :

    dataBinding {
    enabled = true
    } 
    
    0 讨论(0)
提交回复
热议问题