我将项目升级到Gradle插件3.0.1,但在数据绑定类生成期间,我收到以下错误(并且未生成绑定类):
error: cannot generate view binders java.lang.NullPointerException
at android.databinding.tool.store.SetterStore.getMatchingMultiAttributeSetters(SetterStore.java:642)
at android.databinding.tool.store.SetterStore.getMultiAttributeSetterCalls(SetterStore.java:529)
at android.databinding.tool.BindingTarget.resolveMultiSetters(BindingTarget.java:221)
at android.databinding.tool.LayoutBinder.<init>(LayoutBinder.java:249)
at android.databinding.tool.DataBinder.<init>(DataBinder.java:52)
at android.databinding.tool.CompilerChef.ensureDataBinder(CompilerChef.java:90)
at android.databinding.tool.CompilerChef.sealModels(CompilerChef.java:203)
at android.databinding.annotationprocessor.ProcessExpressions.writeResourceBundle(ProcessExpressions.java:193)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
...
经过一些调查,如果我在布局xml中的给定元素上使用数据绑定最多有1个属性,则似乎正确生成了绑定类。如果我添加第二个,我会得到之前的例外。
在我的项目环境中,以下视图会导致错误,但不幸的是,在一个全新的项目中,它会正常编译。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<import type="android.view.View"/>
<variable
name="title"
type="String"/>
<variable
name="visible"
type="boolean"/>
</data>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- with either text or visiblility, the project builds, but not with both -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{title}"
android:visibility="@{visible ? View.VISIBLE : View.GONE}"
/>
</RelativeLayout>
</layout>
有没有人遇到过这个问题?