databinding does not exist: How to solve it?

22,869

Solution 1

This problem occurs usually if your project does not compile. Android databinding should generate code in the named package, but it can't do that if the project doesn't compile in the first place.

To solve this, bring your project to a point where it compiles. If necessary, turn databinding off for this.

Solution 2

check out your xml files and comment any @{} you have used unless you actually have your data ready at hand. With no data, you'll bump into this error again and again and again.

Solution 3

To see the error, just edit these lines of code in the app's build.gradle:

dataBinding {
enabled = false
} 

In this way, the last error in your build console is the actual error. Because from the first to the penultimate error, they are all related to the non-generation of the data binding classes, precisely because we have disabled it.

Once you find the error you will enter again :

dataBinding {
enabled = true
} 

Solution 4

I came across this issue in a project of 4 modules in Android Studio 2.3, it is what @F43nd1r indicated, but want to document what I did to resolve this in my case.

One of the 4 modules had an older Android Support library in in the Gradle file for it, while the other 3 were current. This is what prevented the project from compiling properly and causing the databinding error.

The difficult part was that you don't know about this unless you open each build.gradle file and see if there is an error displayed. It did NOT show an error for it on compile.

Effectively I updated this area to the newer version number to match the other 3 module build.gradle files.

dependencies {
    ...
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:support-v4:25.2.0'
    compile 'com.android.support:recyclerview-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'
    ...
}

Solution 5

dataBinding {
    enabled = true
}

enabled the data binding in app build.gradle file. its worked

Share:
22,869
H. Pauwelyn
Author by

H. Pauwelyn

I'm H. Pauwelyn, I'm working as software and web engineer at Savaco loving AI, robotics, new media, IoT, domotics, the cloud and Lego. The most common programming languages I use are C#, JavaScript, TypeScript and SQL.

Updated on July 09, 2022

Comments

  • H. Pauwelyn
    H. Pauwelyn almost 2 years

    I'm working on an Android application with databinding but I've always next error:

    Error: Package my.package.databinding does not exist.

    Here is my build.gradle on project level:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.2.2'
        }
    }
    allprojects {
        repositories {
            jcenter()
        }
    }
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    I've also enabled binding in the build.gradle file on module level.

    Now my question is, why occurs this error and how could I solve it?

  • Jan Heinrich Reimer
    Jan Heinrich Reimer over 7 years
    Defining the support library version in your project level build.gradle file would help keeping the modules in sync
  • Mansuu....
    Mansuu.... over 4 years
    this tag does not make any sense in my case
  • Elvedin Hamzagic
    Elvedin Hamzagic about 4 years
    In my case the project compiled, but the problem had not been resolved until the module 'com.android.tools.build:gradle' in build.gradle was updated.
  • joe blogs
    joe blogs almost 4 years
    although my project compiled, without binding on, just disabling->compiling->re-enabling and compiling again worked for my project