Android Databinding : package does not exist

41,993

Solution 1

Thanks to Yigit!

The issue was not directly link to Android Databinding. There were a bug in the project (some variables not correctly setted)

I would recommend to use gradle with "--debug and --stacktrace" for more informations, it's helping a lot.

Solution 2

earlier my package name was "com.xyz.abc.Models" changing the package name to all small letters "Models" -> "models"

solved the issue.

Solution 3

The bug is not the DataBinding Package, it's a syntactic or logical error. For example, you have the attribute "lastName" in your POJO, but in the layout it's android:text="@{user.lastname}".

Check your "layout" and do Rebuild Project.

Solution 4

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

Solution 5

Make sure your package name start with lowercase letter. in my case issue solved after two hours of struggle

Share:
41,993
Xero
Author by

Xero

Updated on February 05, 2022

Comments

  • Xero
    Xero over 2 years

    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.company.project.databinding does not exist"

    Here my gradle :

    http://pastebin.com/dkXd1Mxr

    and

    http://pastebin.com/n9hkFWGQ

    And here the gradle output :

    https://pastebin.com/w93Rausg

    • yigit
      yigit over 8 years
      Can you share the gradle output as well? (with --debug and --stacktrace)
    • yigit
      yigit over 8 years
      Here is your error: /Users/anthonybernardo/Documents/Geomatic/GeomaticReborn/app‌​/src/main/java/ch/ge‌​omatic/geomaticrebor‌​n/Views/SearchActivi‌​ty.java:69: error: cannot find symbol 10:21:38.018 [ERROR] [system.err] (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search)); Fix it and the project should compile. If not, please provide the full output (not just the error). I want to see the tasks that are run but anyways, fixing this R.id.search should fix your compilation.
    • Xero
      Xero over 8 years
      omg! I was think that it was a issue with Android Databinding... Thank you a lot!
  • mmm111mmm
    mmm111mmm over 8 years
    This was my problem, too. I was passing in an incorrect value into a BindingAdapter. AS2.0 didn't tell me, just the errors about not finding the package above. Fun.
  • Lucas Queiroz Ribeiro
    Lucas Queiroz Ribeiro over 7 years
    This occurs because the "=" means a two way data binding, for buttons does not makes sense but if you use that in some EditText when you change the data in the EditText the data will change in the model too.
  • Alberto M
    Alberto M over 6 years
    thank you. Scrolling should always be the first step.
  • Sukesh Saxena
    Sukesh Saxena over 4 years
    Solve my issue too
  • Nam Le
    Nam Le over 4 years
    This fixes it for me. Is this mentioned anywhere in the docs of DataBinding ?
  • ThiagoYou
    ThiagoYou about 4 years
    You really saved me sir! I was stuck for hours and nothing in the records indicated that.
  • Angus
    Angus about 3 years
    I encountered the same problem and still couldn't figure it out. I am using android studio in windows machine, can you please share the command to use gradle with the --debug and --stacktrace
  • Frischling
    Frischling over 2 years
    What's funny, adding this to my build gradle seems to fix the problem apply plugin: 'kotlin-android-extensions
  • Basit Ali
    Basit Ali over 2 years
    Solved my issue. Great @Kamlesh Sahu
  • Pishang Ujeniya
    Pishang Ujeniya over 2 years
    Thanks @Caner, for me it was issue that I named a package starting with Capital Letter.
  • Balflear
    Balflear over 2 years
    Thanks, i need it to update from Arctix Fox to Bumblebee and updating the gradle plugin to the lastest for fixing the issue with databinding package.
  • Gk Mohammad Emon
    Gk Mohammad Emon about 2 years
    Really helpful answer 10+