Jetpack databinding generated duplicate class in same file as same class

James Black :

This morning I got an error where my app won't install and I have traced it down to this problem. I have two of the same class in the same file. I don't want to include the entire generated file as it is very long.

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;
:
}

In gradle.properties I have this: android.databinding.enableV2=true

My layout is pretty simple:

<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>

I am using Android Studio 3.3 Canary 3

Sometimes I get that there is a duplicate class in my layout file and then it can't find the DataBindingComponent. What is annoying is that this worked yesterday and I haven't changed the binding since then.

Any suggestions as to what may be the issue?

I have deleted .gradle and mobile/build/* and did a clean and rebuild multiple times, as well as exiting and restarting Android Studio.

I have three layout files with databinding and all three have the same errors.

cherif :

Delete the compiler dependency, it is provided with binding plugin from 3.2.0. At least it worked for me.

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=82057&siteId=1