Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using data-binding in android error: package *.*.databinding does not exist

I'm trying to implement data-binding in android app. This is the link I'm following to set it up. Even after doing all the necessary implements, I'm getting the following error in gradle-build:

error: package com.example.satpracticeapp.databinding does not exist.

(This package is what I'm importing in my MainActivity.java file) I tried this (the data-binding compiler), but it didn't work.

The problem is I've already successfully tried a hello-world app using data-binding and it works. But, when I try to implement it in an app I made a few weeks ago, I get the error I mentioned above. Searching for the solutions, I copy-pasted the gradle files from my successful hello world app to my old app - that too didn't work out.

Here is my app level build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.satpracticeapp"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.0'
}

And here's the buildscript of the project level build.gradle file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

Here are the links to the minimal version of the three files (if it's needed)

  1. MainActivity.java
  2. ViewModel.java
  3. activity_main.xml

After much hair-pulling, I couldn't figure out the solution and getting the same build error again and again. So, as a temporary solution, I'm trying to copy-paste my classes and layouts in the working hello world project. What am I missing?

EDIT:

After a few hours of pointless searching, I went back to my code. Checked it word by word and found a typing mistake at the name of a binding variable in the xml file. Everything works fine now!

like image 428
Akeshwar Jha Avatar asked Dec 20 '15 18:12

Akeshwar Jha


1 Answers

I had the same issue, turned out to be a duplicate symbol declaration in one of my *.java classes. It's shown in the Gradle console but it was kinda hidden among the databinding errors. i had about 72 data binding errors and this duplicate symbol error was in the middle so it's easy to miss.

like image 177
newDeveloper Avatar answered Oct 29 '22 18:10

newDeveloper