【发布时间】:2015-10-26 10:25:51
【问题描述】:
我尝试在现有项目中使用数据绑定,但无法构建它。
项目中使用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
【问题讨论】:
-
由于这个错误是由数据绑定引发的,我没有可以开始搜索该错误的行,并且它是在添加数据绑定后出现的。
标签: android android-databinding