无法使Android数据绑定插件工作

aly*_*aly 4 android android-gradle-plugin android-databinding

我试图使用android数据绑定插件到目前为止没有运气.

我正在使用:Gradle 2.2.1; Intellij IDEA 15.

项目级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()
    }
}
Run Code Online (Sandbox Code Playgroud)

模块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'
}
Run Code Online (Sandbox Code Playgroud)

在尝试更改插件版本时,我遇到了一些不同的错误; 我现在得到的错误是"错误:Gradle:配置项目时遇到问题':app4'.

无法通知项目评估监听器.android.databinding.tool.LayoutXmlProcessor(Ljava /朗/字符串; Landroid /绑定/工具/编剧/ JavaFileWriter; IZLandroid /绑定/工具/ LayoutXmlProcessor $ OriginalFileLookup).V"

Ama*_*i82 7

使用新版本的数据绑定库,您不会显式添加数据绑定依赖项,然后应用它.您只需要dataBinding {enabled = true;}其他问题:此时您的目标SDK版本可能不应该是10.

例:

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()
    }
}
Run Code Online (Sandbox Code Playgroud)

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
}
Run Code Online (Sandbox Code Playgroud)

我不记得neenbedankt gradle插件是否是严格必要的,但它对编译时注释处理非常有用.