TransWikia.com

Android Databinding : package does not exist

Stack Overflow Asked by Xero on November 4, 2021

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

18 Answers

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).

Answered by Cory Charlton on November 4, 2021

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'

Answered by MeStTrE on November 4, 2021

in my case, i follow the android documentation :

buildFeatures {
    viewBinding true
}

use "=" instead of space

buildFeatures {
    viewBinding = true
}

Answered by hammadsyr on November 4, 2021

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.programmerbrain.activity.ContactInfo; //Problem is ContactInfo, 'C'.

Example, TRUE usage:

package com.programmerbrain.activity.contactInfo; //Solution is contactInfo, 'c'.

Answered by canerkaseler on November 4, 2021

Change

{ databinding = true}

to

buildFeatures{
     dataBinding = true
    
}

Answered by Crucialjun on November 4, 2021

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

Answered by Mohd Qasim on November 4, 2021

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

Answered by Siddharth Vaish on November 4, 2021

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

solved the issue.

Answered by Kamlesh Sahu on November 4, 2021

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

Answered by Srinivas Gooduri on November 4, 2021

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

Answered by Khemraj Sharma on November 4, 2021

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.

Answered by Ifta on November 4, 2021

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.

Answered by Harshal baraskar on November 4, 2021

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.

Answered by Oscar Josue Alvrez on November 4, 2021

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

Answered by YTerle on November 4, 2021

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

Answered by Liviu on November 4, 2021

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()}"/>

Answered by vishal gupta on November 4, 2021

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.

Answered by Edhy on November 4, 2021

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.

Answered by Xero on November 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP