Android Databinding : package does not exist
Asked Answered
A

22

31

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

Angelus answered 26/11, 2015 at 8:58 Comment(3)
Can you share the gradle output as well? (with --debug and --stacktrace)Urinary
Here is your error: /Users/anthonybernardo/Documents/Geomatic/GeomaticReborn/app/src/main/java/ch/geomatic/geomaticreborn/Views/SearchActivity.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.Urinary
omg! I was think that it was a issue with Android Databinding... Thank you a lot!Angelus
A
42

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.

Angelus answered 26/11, 2015 at 9:35 Comment(2)
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.Desantis
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 --stacktraceBuenrostro
P
38

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

solved the issue.

Papa answered 11/8, 2019 at 19:24 Comment(3)
Solve my issue tooProcne
This fixes it for me. Is this mentioned anywhere in the docs of DataBinding ?Willin
Solved my issue. Great @Kamlesh SahuVegetative
M
12

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.

Ministerial answered 17/12, 2016 at 4:20 Comment(0)
E
7

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

Extender answered 1/8, 2018 at 19:14 Comment(0)
A
7

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

Acquiescent answered 17/6, 2019 at 6:18 Comment(2)
You really saved me sir! I was stuck for hours and nothing in the records indicated that.Eudosia
Really helpful answer 10+Desiccator
R
4

enter image description here

Package name should start with small letter. for example Activities is wrong it'll give an error instead refactor->rename to activities

Report answered 20/12, 2019 at 16:9 Comment(1)
this is usfull to me thanks proDemonology
S
2

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()}"/>
Schweiz answered 24/2, 2017 at 11:47 Comment(1)
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.Febricity
L
2

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
Lovieloving answered 15/7, 2017 at 11:53 Comment(0)
V
2

On my particular case, I was using Dagger 2. This package error appears in a lot of classes without any relation with the original error: a dependency injection error.

Happy reminder: Scroll more on your stacktrace to know what is the real problem.

Verulamium answered 9/11, 2017 at 21:25 Comment(1)
thank you. Scrolling should always be the first step.Boonie
P
2

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.

Penta answered 29/7, 2018 at 10:45 Comment(0)
P
2

Package names have to START with Small Letters. Otherwise, Binding library cannot understand that is it class or package. Moreover, you do NOT need to do all of it with small letters.

Example, wrong usage:

package com.thecompany.activity.ContactInfo; //Problem is ContactInfo, 'C'.

Example, TRUE usage:

package com.thecompany.activity.contactInfo; //Solution is contactInfo, 'c'.
Pleochroism answered 15/1, 2021 at 18:36 Comment(1)
Thanks @Caner, for me it was issue that I named a package starting with Capital Letter.Contemplate
I
1

Make sure your model's fields you reference in layout have public access modifiers

Irrepressible answered 21/7, 2017 at 21:3 Comment(0)
L
1

Change

{ databinding = true}

to

buildFeatures{
     dataBinding = true
    
}
Lotte answered 21/7, 2020 at 8:38 Comment(0)
S
1

If you're coming to this question because you switched to JDK11 in Android Studio Artic Fox and your view binding broke in the UI but not during execution then be aware that this is a known issue and should be resolved in Bumble Bee:

https://issuetracker.google.com/issues/180946610

The current fix is to switch back to JDK8 (or install the Bumble Bee canary release).

Sucrose answered 3/9, 2021 at 18:30 Comment(2)
What's funny, adding this to my build gradle seems to fix the problem apply plugin: 'kotlin-android-extensionsFeathered
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.Leto
A
0

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.

Actinic answered 11/2, 2018 at 11:41 Comment(0)
S
0

if you tried this steps

  1. invalidate/restart`
  2. keeping this properties in gradel.properties
android.databinding.enableV2=false
android.enableExperimentalFeatureDatabinding=true

and checking all xml files looks good. then you should go with this solution, add below code in project level build.gradle

    allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xmaxerrs" << "1000"
        }
    }
}

this will give you exact error where you have actual error explanation: above code will increase the size of the compile error

Sanction answered 6/4, 2020 at 17:11 Comment(0)
S
0

in my case, i follow the android documentation :

buildFeatures {
    viewBinding true
}

use "=" instead of space

buildFeatures {
    viewBinding = true
}
Stricklin answered 22/1, 2021 at 2:59 Comment(0)
D
0

Try following Refactor -> migrate to androidx

and in the build.grade(:app)

implementation 'androidx.appcompat:appcompat:1.0.0'

or use new version is released

implementation 'androidx.databinding:databinding-runtime:4.1.0'
Dreary answered 10/5, 2021 at 15:15 Comment(0)
M
0

Make sure that if your layout filename is named in the following format: <name>_activity.xml that your binding class name complies the following format as well: <name>ActivityBinding

For me, changing my layout filename from activity_login.xml to login_activity.xml resolved this issue because my binding class name was LoginActivityBinding.

Here's an except from the Android Layouts and binding expressions page mentioning this:

A binding class is generated for each layout file. By default, the name of the class is based on the name of the layout file, converting it to Pascal case and adding the Binding suffix to it. The above layout filename is activity_main.xml so the corresponding generated class is ActivityMainBinding

Munsey answered 13/12, 2021 at 16:46 Comment(0)
S
0

if you use a model in your layout, make sure you dont have the model and the package named same and also the paackage name should start with small letter.

i changed mine from Model>Model.class to modelPac>Model.class

Sisto answered 17/8, 2022 at 4:41 Comment(0)
C
0

In my case the problem appeared when I was creating productFlavors and set sourceSets. Changing

sourceSets {
    develop {
        res.srcDirs = ['myApp/src/develop/res']
    }

to

sourceSets {
    develop {
        res.srcDirs = ['src/develop/res']
    }
}

solved my issue.

Creeps answered 9/11, 2022 at 19:21 Comment(0)
A
0

Hope this will help someone. In my case I was using ZoomImageView which i Programmed in Java file and was using in XML. When i migrated my project to another. The package name changed and i copied same xml file to new project. Which was causing conflict.

I changed

<com.coremacasia.okk.utility.ZoomImageView
    android:id="@+id/zoomImage"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

To

<in.theclink.clink.utility.ZoomImageView
    android:id="@+id/zoomImage"
    android:adjustViewBounds="true"
    android:scaleType="fitCenter"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

It worked.

Actinoid answered 3/6, 2023 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.