Search code examples
androiddata-bindingandroid-constraintlayoutandroid-databinding

Databinding not working with constraint layout Groups


I have used group views in my layout fragment_hurdle_otp.xml file.

.
.
.

<android.support.constraint.Group
            android:id="@+id/group_navigate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:constraint_referenced_ids="iv_navigate_option,tv_navigate_option" />


        <ImageView
            android:id="@+id/iv_navigate_option"
            android:layout_width="@dimen/space_16"
            android:layout_height="@dimen/space_16"
            android:layout_marginStart="@dimen/default_space_24"
            app:layout_constraintBottom_toBottomOf="@+id/tv_navigate_option"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/tv_navigate_option"
            app:srcCompat="@drawable/outline_lock_vector" />

        <TextView
            android:id="@+id/tv_navigate_option"
            style="@style/LoginButtonLight"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/wh_40"
            android:layout_marginTop="@dimen/default_space"
            android:layout_marginBottom="@dimen/default_margin_8"
            android:padding="@dimen/default_space_small"
            android:text="@{vm.tvNavigateOption}"
            app:layout_constraintBottom_toTopOf="@+id/tv_verify"
            app:layout_constraintStart_toEndOf="@+id/iv_navigate_option"
            android:background="@drawable/white_selectable_item_background"
            android:onClick="@{()->vm.onNavigate()}"
            tools:text="@string/login_with_password" />
.
.
.


But while building , generating the Binding files for this layout fails and throws a compilation error.

Class elements: (java.lang.String,java.lang.String)void init /Users/.../../..application/build/generated/data_binding_base_class_source_out/developersProductionDebug/dataBindingGenBaseClassesDevelopersProductionDebug/out/com/phone/app/databinding/FragmentHurdleOtpBinding.java:27: error: cannot find symbol public final Group groupNavigate;

Everything works fine if I remove the group views.


Solution

  • You have already migrated your project to AndroidX. So, You have to use AndroidX library instead of Support. In your project don't mix Support library with AndroidX.

    Use

    androidx.constraintlayout.widget.Group
    

    instead of

    android.support.constraint.Group
    

    Also include AndroidX library of ConstraintLayout in your module level build.gradle

    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'