Android Databinding : package does not exist

前端 未结 15 1153
暗喜
暗喜 2020-12-06 04:19

I\'m trying to use data-binding with Android.

I can not anymore build my project. I got this error :

\"Error:(13, 46) error: package ch.compan

相关标签:
15条回答
  • 2020-12-06 04:44

    I am not satisfied with accepted answer, that tell you to stack trace without hints.

    Here are some possible causes that lead to this problem. Check if you are not doing any of the following.

    Basically Android DataBinding is not that mature still. It will fail without appropriate errors many times.

    So if you have an issue like package ch.company.project.databinding does not exist".

    Possible causes of fail:

    • First of all check your recently edited layouts xml one by one for errors (for wrong imports & variables). I don't get proper error in this case usually.

    • Check your data binding syntax in binding block ({...}) in layout element for errors. Always Rebuild (not Build) project after working in one layout.

    • Check your @BindingAdapter method having correct parameters. For example imageUrl binding adapter would accept ImageView or View as first parameter.

    • You should always Rebuild project after doing work in one layout.

    • If you are not able to find errors by above steps, then try --debug and --stacktrace in compile option of

      File> Settings> Build, Execution, Deployment> Compiler> Command-line Options

    0 讨论(0)
  • 2020-12-06 04:45

    To get rid of this error just enclose your complete layout design inside a plain layout tag in the activity_main.xml file.

    After wasting many hours in finding solution this worked for me. Give it a try.

    0 讨论(0)
  • 2020-12-06 04:46

    I had similar problems with my project

    You could try:

    • check xml files for errors that cause a build failure
    • clean project
    • File -- invalidate caches / restart
    0 讨论(0)
  • 2020-12-06 04:47

    Change

    { databinding = true}
    

    to

    buildFeatures{
         dataBinding = true
        
    }
    
    0 讨论(0)
  • 2020-12-06 04:50

    I was stuck with same error for hours. After trying several solution from stackoverflow, I updated my project with stable gradle dependencies.

    Still it was not solved, however with the same gradle dependency DataBinding was working fine in another project of mine.

    So, I went project folder using explorer and Deleted 2 things.

    1. build folder
    2. all files from .idea/libraries

    After that i synced the project and it continued to work just fine.

    0 讨论(0)
  • 2020-12-06 04:54

    I got the error:

    Error:(9, 46) error: package com.company.www.bar.databinding does not exist.

    i just remove "=" sign . it worked for me

    From this :

     <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="@={()->activity.onButtonClick()}"/>
    

    to :

    <Button
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:onClick="@{()->activity.onButtonClick()}"/>
    
    0 讨论(0)
提交回复
热议问题