'Hilt Data binding: One specific view is getting "Could not find identifier"

I have a working app with Hilt. Added the layout below but this specific spinner view is having problems while the rest is working fine. The spinner data binding itself is working and entries being populated, but for some reason this part cannot find the view id tags_spinner.

<ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:onClick="@{(view) -> viewModel.process(tags_spinner)}"/>

The unusual thing is the other image button can find its target view just fine.

`<ImageButton
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:onClick="@{(view) -> viewModel.process(tag)}"/>`

My app is running on these versions:

hilt_version = '2.40.5'
lifecycle_version = '2.4.1'
kapt_version = '1.6.20-RC'

Layout code below.

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

        <variable
            name="viewModel"
            type="com.base.BaseActivityViewModel" />

        <variable
            name="adapter"
            type="android.widget.ArrayAdapter" />

        <import type="android.view.View"/>

    </data>

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <EditText
            android:id="@+id/trackerNameEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Page Name"
            android:text="@={viewModel.page.pageName}"
            app:layout_constraintTop_toTopOf="parent"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/trackerNameEditText">

            <Spinner
                android:id="@+id/tags_spinner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                tools:listitem="@android:layout/simple_spinner_dropdown_item"
                android:setAdapter="@{adapter}"
                android:entries="@{viewModel.tagsList}"/>

            <ImageButton
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:onClick="@{(view) -> viewModel.process(tags_spinner)}"/>

            <EditText
                android:id="@+id/tag"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:hint="New Tag"/>

            <ImageButton
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:onClick="@{(view) -> viewModel.process(tag)}"/>

        </LinearLayout>


    </androidx.constraintlayout.widget.ConstraintLayout>

</layout>


Solution 1:[1]

Found that it is a bug which I haven't fully understood yet, it causes the problem when assigning view ids containing an undescrore _. Simply changing my assignment to "@+id/tagsSpinner" fixed the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jose