Access Binding Adapters in multi module project

北战南征 提交于 2021-01-27 19:41:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!