【发布时间】:2019-10-09 13:38:13
【问题描述】:
我在我的项目中使用 DataBinding。使用 Java,不是 Kotlin,Android Studio 版本是 3.5.1(最新)
将项目 gradle 版本从 3.5.0 升级到 3.5.1 后,*BindingImpl 类中出现错误。 我发现问题出在我的一个布局文件中的 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 一切都会好起来的,但正如您所见并非如此((
【问题讨论】:
-
一周前我问过,我应该在 Google Tracker 中打开问题吗?
标签: android gradle android-databinding generated-code