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
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"
.
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
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.
I had similar problems with my project
You could try:
Change
{ databinding = true}
to
buildFeatures{
dataBinding = true
}
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.
- build folder
- all files from .idea/libraries
After that i synced the project and it continued to work just fine.
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()}"/>