4

I'm not able to setup my project to use Android Data Binding. This is my build.gradle:

apply plugin: 'com.android.databinding'


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

android {
    ...
    dataBinding {
        enabled = true
    }

    compileSdkVersion 21
    buildToolsVersion "20.0.0"
    ...
}

When I build, I get this error:

[data binding plugin]: failed to setup data binding

java.lang.NoSuchMethodError: android.databinding.tool.LayoutXmlProcessor.(Ljava/lang/String;Ljava/util/List;Landroid/databinding/tool/writer/JavaFileWriter;IZ)V

EDIT

I have modified build.gradle:

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

But I still get the same error. Also I have this apt config:

apt {
    arguments {
        androidManifestFile variant.outputs[0].processResources.manifestFile
    }
}

Since I'm using AndroidAnnotations.

1
  • remove classpath "com.android.databinding:dataBinder:1.0-rc4". Commented Dec 3, 2015 at 4:47

2 Answers 2

6

You should now set it up with 1.5.0 and without the explicit data binding import:

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

Android Data Binding 1.0 was released as part of the Android gradle plugin.

Sign up to request clarification or add additional context in comments.

2 Comments

I have tried this but get the same error. Look at my edit.
Hmm... Do you still have the apply plugin: 'com.android.databinding'? If so, you should remove that. You may have a stray dependencies { classpath 'com.android.databinding:dataBinder:1.0-rc4' } in a root build.gradle. If that's not it, perhaps you can post a project that I can look at.
4

Though George's answer is correct I think it's important to make it clear what should be in each one of the build.gradle files.

So, in the project's build.gradle file we should have:

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

And in the app's build.gradle file there should be:

apply plugin: 'com.android.application'
// No need to add it as a plugin
// apply plugin: 'com.android.databinding'

android {
    ...
    dataBinding {
        enabled = true
    }

    compileSdkVersion <latest>
    buildToolsVersion <latest>
    ...
}

We don't need to add apply plugin: 'com.android.databinding' in the app's build.gradle file because, as George said:

Android Data Binding 1.0 was released as part of the Android gradle plugin.

Check the Data Binding Guide for more details.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.