6

I've got a multi module project where the app module contains my binding adapters and my feature module depends on my app module since it is a dynamic feature module.

App (contains binding adapters) ----> Dynamic feature module (where the layout is present)

I have databinding and kapt enabled in all the modules.

I'm unable to build the app successfully. Android Studio gives me the following error,

error: cannot find symbol
import com.app.module1.databinding.FeatureItemBindingImpl;

Layout file in dynamic feature module:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="item"
            type="com.app.module1.views.FeatureItem" />

        <variable
            name="clickListener"
            type="com.app.module1.views.FeatureRecyclerViewAdapter.FeatureItemClickListener" />
    </data>

    <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_margin="10dp"
        app:cardElevation="3dp"
        android:id="@+id/card"
        android:onClick="@{(view) -> clickListener.onClickFeature(view, item)}">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/feature_image"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="7"
                android:scaleType="fitXY"
                app:set_image="@{item.featureImage}"
                tools:src="@color/green_200" />

            <com.google.android.material.textview.MaterialTextView
                android:id="@+id/feature_name"
                style="@style/TextAppearance.MyTheme.Body2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="1"
                android:gravity="center"
                android:text="@{item.featureName.featureTitle}"
                tools:text="Order Pills" />
        </LinearLayout>

    </com.google.android.material.card.MaterialCardView>
</layout>

Binding Adapter in the App module:

@BindingAdapter("set_image")
fun AppCompatImageView.setImageToImageView(@DrawableRes drawable: Int) {
    this.setImageResource(drawable)
}
  • What does your layout and data header look like in the xml file? Also, when I was getting these errors and couldn't find any problems with the xml syntax I had to clean the project. Usually this fixed the issues. – chrisdottel Jun 06 '20 at 23:40
  • @AnonAnonym updated the post – Jitendra Reddy Jun 07 '20 at 00:00
  • @AnonAnonym I tired cleaning build and caches but it didn't work – Jitendra Reddy Jun 07 '20 at 00:11
  • Hi, this is possible duplicate to https://stackoverflow.com/questions/63176547/cannot-find-bindindadapter-in-dynamic-feature-module It seems that binding adapter defined in app module is not accessible from feature module. Look closely at log from kapt task, I bet you will see errors such as "Cannot find a setter for ". When you move or copy the binding adapter to the feature module it works. – smuk Dec 09 '20 at 17:53

1 Answers1

2

I had the same problem because I was trying to access the class in the other module. It fixed when I put the class I was trying to access into the module containing xml. You can access only the classes in that module from within the XML.

Gamze
  • 21
  • 4