Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot make Android databinding plugin work

I am trying to make use of the android databinding plugin with no luck so far.

I am using: Gradle 2.2.1; Intellij IDEA 15.

Project level build.gradle:

buildscript {
repositories {
    jcenter()
}
dependencies {

    classpath 'com.android.tools.build:gradle:1.5.0'
    classpath "com.android.databinding:dataBinder:1.0-rc2"

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

allprojects {
repositories {
    jcenter()
    }
}

Module build.gradle:

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

buildscript {
repositories {
    jcenter()
}
dependencies {

}
}

repositories {
jcenter()
}

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.example.app4.app4"
    minSdkVersion 10
    targetSdkVersion 10
    versionCode 1
    versionName "1.0"
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_6
    targetCompatibility JavaVersion.VERSION_1_6
}
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'
}

I got few different errors while trying to change plugins' versions; the error I am getting now is "Error:Gradle: A problem occurred configuring project ':app4'.

Failed to notify project evaluation listener. android.databinding.tool.LayoutXmlProcessor.(Ljava/lang/String;Landroid/databinding/tool/writer/JavaFileWriter;IZLandroid/databinding/tool/LayoutXmlProcessor$OriginalFileLookup;)V"

like image 541
aly Avatar asked Mar 14 '23 15:03

aly


1 Answers

With the new version of the data binding library, you don't explicitly add the databinding dependency then apply it. All you need is dataBinding{enabled = true;} Other concerns: your target SDK version should probably not be 10 at this point.

Example:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

and

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.yourappname"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0" 


    buildTypes {
        release {
            minifyEnabled false
            shrinkResources false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        enabled = true;
    }
}

dependencies {
    //other dependencies
}

I don't recall if the neenbedankt gradle plugin is strictly necessary, but it's very useful for compile time annotation processing.

like image 90
Jim Pekarek Avatar answered Mar 25 '23 07:03

Jim Pekarek