Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

databinding does not exist: How to solve it?

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?

like image 521
H. Pauwelyn Avatar asked Nov 05 '16 16:11

H. Pauwelyn


People also ask

What is DataBinding in Java?

The Data Binding Library is a support library that allows you to bind UI components in your layouts to data sources in your app using a declarative format rather than programmatically. Layouts are often defined in activities with code that calls UI framework methods.

Can we use DataBinding and ViewBinding together?

You can't use them togheter in the same layout. ViewBinding is a subset of what DataBinding can do and should be used if you want to replace libraries like ButterKnife , KotterKnife or KAE (Kotlin Android Extensions) but don't want to invest in databinding refactoring.

Which is better ViewBinding and DataBinding?

The one and only function of View Binding is to bind the views in the code, while Data Binding offers some more options like Binding Expressions, which allows us to write expressions the connect variables to the views in the layout.


1 Answers

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.

like image 163
F43nd1r Avatar answered Sep 17 '22 18:09

F43nd1r