22

This is an old question which is irrelevant today. See Android developer's instruction. Applying Databinding to your projects is a lot easier now than four years ago.

As I am going over Android Data binding Guide from https://developer.android.com/tools/data-binding/guide.html. I have made sure I am running Android Studio 1.3 (canary version).

Following the guidelines, I get this error:

Gradle sync failed: could not find com.android.databinding:library:1.0-rc0

Has anyone else have the same problem? Thanks for your help.

App build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0-beta1'
        classpath "com.android.databinding:dataBinder:1.0-rc0"
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Module build.graddle

apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'

apply plugin: 'android-apt'
def AAVersion = '3.3'
def MyProject = 'com.commonsware.android.frw.filesdemo'

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    }
}

repositories {
    mavenCentral()
}

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
        resourcePackageName "$MyProject"
    }
}

android {
    compileSdkVersion 22
    buildToolsVersion "22"

    defaultConfig {
        applicationId "$MyProject"
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions{
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/services/com.fasterxml.jackson.core.JsonFactory'
    }

    dexOptions {
        preDexLibraries = false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

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

    compile "com.squareup:otto:1.3.6"
    compile "commons-io:commons-io:+"
    compile 'com.fasterxml.jackson.jr:jackson-jr-all:2.5.0'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'

    apt "org.androidannotations:androidannotations:$AAVersion"
    compile "org.androidannotations:androidannotations-api:$AAVersion"
}
Juan Mendez
  • 2,658
  • 1
  • 27
  • 23
  • Did you ever figure this out? All my stuff was working, and now it's not. I've got gradle build 1.3.0-beta4, and com.android.databinding:library:1.0-rc0, with buildt tools version 23.0.0 rc3. – LukeWaggoner Jul 21 '15 at 22:43
  • 1
    I just figured my issue out. Removing the android-apt plugin caused everything to resolve. Spent two days working on this. Hope this saves someone some time. – LukeWaggoner Jul 21 '15 at 23:39
  • Man I tried everything here, what else could be the problem?? – Mike6679 Apr 11 '16 at 21:30

12 Answers12

16

I had this problem and solved it by adding "jcenter" under allprojects.repositories in my top-level build.gradle (I had been using mavenCentral).

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.android.databinding:dataBinder:1.0-rc1'
    }
}

allprojects {
    repositories {
        mavenCentral()
        jcenter() // <=== *** Adding this fixed it ***
    }
}
DataGraham
  • 1,625
  • 1
  • 16
  • 20
9

I got errors when I sync build.gradle files.

Error:Failed to resolve: com.android.databinding:library:1.0-rc0

Error:Failed to resolve: com.android.databinding:adapters:1.0-rc0

And I finally found the solution.

dependencies {

    // instead of the below pathes...
    //classpath "com.android.tools.build:gradle:1.3.0-beta2"
    //classpath "com.android.databinding:dataBinder:1.0-rc0"

    // I used the following classpathes.... It works!
    classpath "com.android.tools.build:gradle:1.3.+"
    classpath "com.android.databinding:dataBinder:1.+"

}
pretty angela
  • 2,241
  • 1
  • 19
  • 8
6

By looking at your error Gradle couldn't find com.android.databinding:dataBinder:1.0-rc0 you should try this instead,

classpath "com.android.databinding:dataBinder:1.0-rc1"

To use DataBinding follow all these steps.

  1. Update your Android Studio to Android Studio 1.3 version.
  2. To set up your application to use data binding, add data binding to the class path of your top-level build.gradle file, right below "android".

    dependencies {
       classpath "com.android.tools.build:gradle:1.3"
       classpath "com.android.databinding:dataBinder:1.0-rc1"
    }
    
  3. Then make sure jcenter is in the repositories list for your projects in the top-level build.gradle file.

    allprojects {
       repositories {
           jcenter()
       }
    }
    
  4. In each module you want to use data binding, apply the plugin right after android plugin.

    apply plugin: 'com.android.application'
    apply plugin: 'com.android.databinding'
    
  5. Clean and build your app.

Complete code

top-level build.gradle file,

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3'
        classpath "com.android.databinding:dataBinder:1.0-rc1"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

module-level build.gradle file,

apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.packagename"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

For more detail Data Binding Guide.

For Complete demo Data Binding Android

Jaydipsinh Zala
  • 16,558
  • 7
  • 41
  • 45
3

Make sure you have Android Studio 1.3 or higher

Your project build.gradle should look something like this:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0-beta1'
        classpath "com.android.databinding:dataBinder:1.0-rc0"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

And your module build.gradle should look something like this:

apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'

android {

    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.my.appId"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

}

I had a problem where I was targeting M Preview so nothing worked. Once I changed the build tools to 22.0.1, and the targetSdkVersion to 22, everything worked.

Gil Moshayof
  • 16,633
  • 4
  • 47
  • 58
3

I had the same issue and solved it by updating android sdk tools to 24.3.3.

labyrinth
  • 13,397
  • 7
  • 35
  • 44
Ygritte
  • 31
  • 3
3

Update for latest Android Studio & latest Gradle

You don't need to add databinding:dataBinder dependency now. Just enable dataBinding in app level build.gradle in android tag.

android
{
...
    dataBinding {
        enabled = true
    }
...
}
Community
  • 1
  • 1
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
  • thanks Khemraj, this is an old question back in the day when DataBinding wasn't as intergrated to the Android library as it's today, still having only one single databinding direction. Frankly, I left DataBinding for so long until I found out it now supports double binding. I might end up deleting this question. It no longer applies. – Juan Mendez Aug 03 '18 at 17:12
  • Why you left data binding? I did not get you. – Khemraj Sharma Aug 03 '18 at 17:13
  • for example you have a model, and assign the attribute to an EditTextView text="@{model.name}". That was all you could do, and relied on handling the event change in the editTextView. Now you can double bind, meaning this text="@={model.name}" which means the editTextView can update name on its own without having you to add a listener and update name manually. – Juan Mendez Aug 03 '18 at 17:18
  • So that's good ? It is called two-way binding. What's wrong you find in that? – Khemraj Sharma Aug 03 '18 at 17:19
  • I didn't find anything wrong, totally the opposite. Before it was a single-way databinding. That's all – Juan Mendez Aug 03 '18 at 18:38
  • Yes, but I found this amazing, and it reduced my code more than 50% – Khemraj Sharma Aug 03 '18 at 18:43
2

As the Documentation said

To use data binding, Android Plugin for Gradle 1.5.0-alpha1 or higher is required.

I have added the following line to build.gradle project :

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and then add the :

dataBinding {
        enabled = true
    }

to your build.graddle module app like this :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "gujarat.databinding"
        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'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
}
Gujarat Santana
  • 9,854
  • 17
  • 53
  • 75
1

Please, try to change classpath to 'com.android.tools.build:gradle:1.3.0-beta2' and set buildToolsVersion "23 rc2".

Don't forget to update SDK packages via SDK manager before doing that.

Here you can find more information about Android Preview SDK: Set Up the Preview SDK

  • Vladimir, thanks a lot for your help. I had only upgraded Android Studio version and ignored the SDK. After a while upgrading, the error went away and following the changes you pointed out in my configuration files. – Juan Mendez Jun 07 '15 at 22:07
  • Did not work for me. It seems to be looking for this package in the SDK. I updated both the Android and Google repos in my SDK. – Yoel Gluschnaider Jun 09 '15 at 18:04
  • Did work, had a different issue. I work behind an SSL cert so I needed to set the allprojects scope with the http jcenter repo as well. – Yoel Gluschnaider Jun 09 '15 at 18:24
  • Make sure your build tools in SDK Manager is up to date as well. As I was working with other dependency injection, I found that my application wasn't able to get generated classed having Binding as suffix. I had to modify the gradle declarations for that to work, and hope that can help others who are trying to have this running with Dagger, or AndroidAnnotations. https://github.com/juanmendez/jm_android_dev/tree/master/05.parse_read_write/01.fileDrivenPageViewer – Juan Mendez Jun 11 '15 at 01:45
  • @YoelGluschnaider, Ok, I wanted to confirm what I was missing before it got to work was I needed to install or have up to date. Android SDK Platform-tools ( rev. 23 rc2), as well Android SDK Build-tools. – Juan Mendez Jun 11 '15 at 01:53
1

I had an identical issue, and solved it by removing the plugin for android-apt. Not sure what's conflicting there, but something is.

LukeWaggoner
  • 8,869
  • 1
  • 29
  • 28
  • Yes, I also had the same problem, and this answer led me to updating my android-apt to version 1.6 which solved the issue in my build. – Neal Sanche Aug 06 '15 at 19:48
1

You should update your SDK and It will resolve this issue.

TapanHP
  • 5,969
  • 6
  • 37
  • 66
  • Thanks man, two years after it is a lot easier to include DataBinding, and it has grown elegantly. I didn't look at it for a long time and now I got to used it and fell in love with it. – Juan Mendez Oct 26 '17 at 01:07
-1

You should add

classpath 'com.android.tools.build:gradle:1.3.0'
classpath "com.android.databinding:dataBinder:1.0-rc0"

build.grade which in project Directory. then Sync the gradle

-2

Sync your project after adding classpath

Anandu
  • 145
  • 1
  • 4