我尝试在现有项目中使用数据绑定,但无法构建它。
在项目中使用build.gradle
:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
//Data Binding Beta
classpath "com.android.databinding:dataBinder:1.0-rc4"
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.7+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
申请
apply plugin: 'com.android.databinding'
apply plugin: 'com.neenbedankt.android-apt'`
并在模块中:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
apt 'com.android.databinding:compiler:1.0-rc1+'
}
我尝试将数据绑定与 RecyclerView/Fragment/ViewHolder/Adapter 一起使用。我使用的是 Android Studio 1.4.1。使用 compileSdkVersion 23 和 buildToolsVersion "23.0.1"。我在没有 apt、不同的 gradle 版本的情况下尝试了它,校对了我的类/xml。我还使用了 Butterknife(因为我的项目太大而无法一次更改所有内容)和其他(但不相关的)库。我同步并重建了我的项目,我关闭/打开了 Android Studio,我试图使缓存无效。我从一开始就建立了一个“新鲜”的例子,效果很好。
我的“数据类”中的getter 方法是@Bindable。
此外,不会创建数据绑定包。(错误消息说它不存在)和Error:cannot generate view binders java.lang.StringIndexOutOfBoundsException: String index out of range: -21