问题
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)
}
来源:https://stackoverflow.com/questions/62238993/access-binding-adapters-in-multi-module-project