android - 无法使 Android 数据绑定(bind)插件工作

标签 android android-gradle-plugin android-databinding

到目前为止,我正在尝试使用 android 数据绑定(bind)插件,但没有成功。

我正在使用: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()
    }
}

模块构建.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'
}

我在尝试更改插件版本时遇到了几个不同的错误;我现在得到的错误是“错误:Gradle:配置项目':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"

最佳答案

使用新版本的数据绑定(bind)库,您无需显式添加数据绑定(bind)依赖项然后应用它。您只需要 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()
    }
}

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
}

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

关于android - 无法使 Android 数据绑定(bind)插件工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34765580/

相关文章:

android - 如何仅在 Flutter 的 datepicker 中显示年份?

android - 如何将我自己的库发布到 TFS?

java - TextureRegion.split Android工作室错误

如果值为真,Android 数据绑定(bind)设置填充

android - 无法解决 MainActivityBinding 以及绑定(bind)相关问题

java - android 可绘制标记 nullExceptionPointer

android - 我该如何解决? `Failed to resolve: com.crashlytics.sdk.android:crashlytics:com.crashlytics.tools.gradle`

php - 在 android c2dm 中推送通知

gradle - 有没有办法像我们对文件那样通过 gradle 匹配正则表达式的目录?

android - Gradle 找不到 com.android.databinding :dataBinder:1. 0-rc0