java - Jetpack 数据绑定(bind)在同一文件中生成了与同一类相同的重复类

标签 java android android-databinding android-jetpack

今天早上我收到一个错误,我的应用无法安装,我已将其归结为这个问题。我在同一个文件中有两个相同的类。我不想包含整个生成的文件,因为它很长。

public class AddVinDialogFragmentBinding extends androidx.databinding.ViewDataBinding implements android.databinding.generated.callback.OnClickListener.Listener {
    @Nullable
    private static final androidx.databinding.ViewDataBinding.IncludedLayouts sIncludes;
    @Nullable
    private static final android.util.SparseIntArray sViewsWithIds;
 :
    @Nullable
    private com.ui.EventHandler mHandler;
    @Nullable
    private final android.view.View.OnClickListener mCallback1;
    public class AddVinDialogFragmentBinding extends androidx.databinding.ViewDataBinding implements android.databinding.generated.callback.OnClickListener.Listener {

        @Nullable
        private static final androidx.databinding.ViewDataBinding.IncludedLayouts sIncludes;
:
}

gradle.properties 我有这个:android.databinding.enableV2=true

我的布局非常简单:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <data>
        <variable
            name="vin"
            type="String" />
        <variable name="handler" type="com.ui.garage.handlers.EventHandler" />
    </data>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.ui.AddVinDialogFragment">
    <TextView
        android:layout_width="wrap_content"
        android:text="Please enter a VIN"
        android:layout_height="wrap_content" />
    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/add_vin_field"
        android:layout_width="200dp"
        android:maxLength="17"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hint="@string/vin"
        android:text="@={vin}" />
    </com.google.android.material.textfield.TextInputLayout>

    <Button
        android:id="@+id/button"
        android:onClick="@{() -> handler.addVin(vin)}"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/submit" />
</LinearLayout>
</layout>

我正在使用 Android Studio 3.3 Canary 3

有时我发现我的布局文件中有一个重复的类,然后找不到 DataBindingComponent。令人恼火的是,这在昨天有效,从那以后我就没有更改绑定(bind)。

关于可能是什么问题有什么建议吗?

我删除了 .gradle 和 mobile/build/* 并进行了多次清理和重建,以及退出并重新启动 Android Studio。

我有三个带有数据绑定(bind)的布局文件,所有三个都有相同的错误。

最佳答案

删除编译器依赖,从3.2.0开始自带绑定(bind)插件。至少它对我有用。

kapt "com.android.databinding:compiler:$gradleVersion

关于java - Jetpack 数据绑定(bind)在同一文件中生成了与同一类相同的重复类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51522637/

相关文章:

java - 如何将 SQL 日期时间戳转换为人类可读的时间?

android - 禁用某些布局的数据绑定(bind)

Java-我没有从 for 循环和 if 语句中获得输出

java - 从 Firebase 实时数据库检索特定数据的最快方法?

java - 在Java中,哪种按字节读取文件的方法更好:

android - Kotlin 对象加载延迟

android - 如何查找设备类型和其他有关设备的信息

安卓数据库: issue when binding parameters using selectionArgs

android - 膨胀包含数据绑定(bind)的 Viewstub

Android 数据绑定(bind) - 错误 :(119, 29) 标识符必须具有来自 XML 文件的用户定义类型。 main_radio_subscribe 丢失了