错误:<value>与属性<package>不兼容:<attribute_name>(attr)引用[weak]

时间:2018-05-24 17:46:00

标签: java android kotlin android-databinding kapt

我正在尝试整合this库。我得到了一个&#34;缺少属性&#34;的问题,所以我将这些属性添加到我的项目中:

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    <declare-styleable name="app">
        <attr name="isDone" format="boolean"/>
        <attr name="isVisible" format="boolean"/>
    </declare-styleable>
</resources>

之后,当我清理项目并再次运行构建过程时,我遇到了这个问题:

error: '@{viewModel.hasStartDate}' is incompatible with attribute com.example:isVisible (attr) reference [weak].
Message{kind=ERROR, text=error: '@{viewModel.hasStartDate}' is incompatible with attribute com.example:isVisible (attr) reference [weak]., sources=[/home/local/<USER_NAME>/.gradle/caches/transforms-1/files-1.1/DateTimeRangePicker-v1.3.aar/524561517fca999eba7db795be3a768d/res/layout/date_time_range_picker.xml:52], original message=, tool name=Optional.of(AAPT)}

在某些地方,其中一个是由该库使用数据绑定生成的布局文件中的这一行:

    app:isDone="@{viewModel.isCompletable}"

在该库生成的Kotlin代码中,声明了它:

  val isCompletable = ObservableBoolean()

这个图书馆在Kotlin。 造成这种情况的原因是什么?

是KAPT吗? 它是数据绑定吗?

2 个答案:

答案 0 :(得分:0)

声明的属性必须是string类型

    <attr name="isDone" format="string"/>
    <attr name="isVisible" format="string"/>

答案 1 :(得分:0)

Xml布局

<android.support.design.widget.TextInputLayout
      android:layout_width=”match_parent”
      android:layout_height=”wrap_content”
      app:error=”@{loginInfo.passwordError}”>
      <EditText
        android:id=”@+id/password”
        android:layout_width=”match_parent”
        android:layout_height=”wrap_content”
        android:enabled=”@{loginInfo.existingUser}”
        android:hint=”@string/password”
        android:inputType=”textPassword”
        app:binding=”@{loginInfo.password}”/>
    </android.support.design.widget.TextInputLayout>

模型类

public class LoginInfo {
  public BindableBoolean existingUser = new BindableBoolean();
}

BindableBoolean类

import org.parceler.Parcel;

@Parcel
public class BindableBoolean extends BaseObservable {
    boolean mValue;

    public boolean get() {
        return mValue;
    }

    public void set(boolean value) {
        if (mValue != value) {
            this.mValue = value;
            notifyChange();
        }
    }
}