在布局中使用 MutableLiveData 变量时数据绑定停止工作 [Gradle 到 3.5.1]

Data binding stops working when using MutableLiveData variable inside layout [Gradle to 3.5.1]

我在我的项目中使用数据绑定。使用 Java,不是 Kotlin,Android Studio 版本是 3.5.1(最新)

将项目 gradle 版本从 3.5.0 升级到 3.5.1 后,*BindingImpl class 中出现错误。 我发现问题出在我的一个布局文件中的 MutableLiveData

已尝试清理项目并重新启动 Android Studio。但唯一有效的方法是将 gradle 版本设置回 3.5.0

这是我的布局

<?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"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <import type="androidx.lifecycle.MutableLiveData" />

        <variable
            name="hintText"
            type="String" />

        <variable
            name="helperText"
            type="String" />

        <variable
            name="collection"
            type="Object" />

        <variable
            name="selection"
            type="MutableLiveData" /> // this one is breaks down in 3.5.1

        <variable
            name="enabled"
            type="Boolean" />

    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:setupSpinnerHint="@{true}">

        <kz.jgroup.android.umag.base.view.customs.ResizableItemsSpinner
            android:id="@+id/spinner"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:adapterWith="@{collection}"
            android:background="@drawable/spinner_outlined_box"
            android:enabled="@{enabled == null ? true : enabled}"
            android:paddingStart="12dp"
            android:paddingTop="26dp"
            android:paddingEnd="32dp"
            android:paddingBottom="17dp"
            android:selectedItem="@={selection}"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:textSize="16sp"
            tools:listitem="@layout/item_spinner_inline" />

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/hint"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:background="@color/white"
            android:paddingLeft="4dp"
            android:paddingRight="4dp"
            android:text="@{hintText}"
            android:textColor="@color/focusable_color"
            android:textSize="14sp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            tools:text="Подсказка" />


        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/helper_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="4dp"
            android:layout_marginTop="5dp"
            android:emptyToGone="@{helperText}"
            android:textColor="@color/focusable_color"
            android:textSize="12sp"
            app:layout_constraintStart_toStartOf="@+id/hint"
            app:layout_constraintTop_toBottomOf="@+id/spinner"
            tools:text="Вспомогательное сообщение" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</layout>

这是我出错的地方以及 DataBinding 生成的内容

版本 3.5.1

        boolean enabledJavaLangObjectNull = false;
        ? selectionGetValue = null; //Illegal start of expression
        java.lang.Object collection = mCollection;
        boolean enabledJavaLangObjectNullBooleanTrueEnabled = false;
        java.lang.String helperText = mHelperText;
        androidx.lifecycle.MutableLiveData<?> selection = mSelection;
        java.lang.String hintText = mHintText;
        java.lang.Boolean enabled = mEnabled;

在 3.5.0 版本中生成的代码看起来是:

        boolean enabledJavaLangObjectNull = false;
        java.lang.Object selectionGetValue = null;
        java.lang.Object collection = mCollection;
        boolean enabledJavaLangObjectNullBooleanTrueEnabled = false;
        java.lang.String helperText = mHelperText;
        androidx.lifecycle.MutableLiveData selection = mSelection;
        java.lang.String hintText = mHintText;
        java.lang.Boolean enabled = mEnabled;

我预计从稳定版 3.5.0 升级到稳定版 3.5.1 一切都会好起来的,但如您所见,情况并非如此((

已在 3.5.2 中修复:

https://androidstudio.googleblog.com/2019/11/android-studio-352-available.html

以及问题本身:

https://issuetracker.google.com/issues/141633235