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



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

我使用的是:等级2.2.1;Intellij IDEA 15。

项目级建筑.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"时出现问题。

未能通知项目评估侦听器。android.databinding.tool.LayoutXmlProcessor。(Ljava/lang/String;Landroid/databinding/tool/writer/JavaFileWriter;IZLandroid/diatabinding\tool/LayoutXmlProcesser$OriginalFileLookup;)V"

使用新版本的数据绑定库,您不会显式添加数据绑定依赖项然后应用它。您只需要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插件是否是严格必要的,但它对编译时注释处理非常有用。

最新更新