I have extension function in app module
@BindingAdapter("imageSrc")
fun setImageUrl(view: ImageView, userId: Int) {
try {
val drawableRes = when {
userId % 6 == 0 -> {
R.drawable.avatar_1_raster
}
userId % 6 == 1 -> {
R.drawable.avatar_2_raster
}
userId % 6 == 2 -> {
R.drawable.avatar_3_raster
}
userId % 6 == 3 -> {
R.drawable.avatar_4_raster
}
userId % 6 == 4 -> {
R.drawable.avatar_5_raster
}
else -> {
R.drawable.avatar_6_raster
}
}
val requestOptions = RequestOptions()
requestOptions.placeholder(R.drawable.ic_launcher_background)
Glide
.with(view.context)
.setDefaultRequestOptions(requestOptions)
.load(drawableRes)
.into(view)
} catch (e: Exception) {
e.printStackTrace()
}
}
it works fine when it's used in a layout in app module but when it's called from the same layout that is in a dynamic feature module results compile error below
[databinding] {"msg":"Cannot find a setter for
\u003candroidx.appcompat.widget.AppCompatImageView app:imageSrc\u003e
that accepts parameter type \u0027int\u0027\n\nIf a binding adapter
provides the setter, check that the adapter is annotated correctly and
that the parameter type
matches.","file":"features/post_detail/src/main/res/layout/fragment_post_detail.xml","pos":[{"line0":19,"col0":28,"line1":19,"col1":38}]}
Layout that uses this binding
<?xml version="1.0" encoding="utf-8"?>
<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="item"
type="com.smarttoolfactory.tutorial8_2dynamicfeatures_complexarchitecture.api.Post" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/ivAvatar"
imageSrc="@{item.userId}"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/avatar_1_raster"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:gravity="center"
android:text="@{item.title}"
android:textSize="26sp"
android:inputType="textCapWords"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@id/ivAvatar"
app:layout_constraintStart_toStartOf="@id/ivAvatar"
app:layout_constraintTop_toBottomOf="@id/ivAvatar"
tools:text="Sample Title" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tvBody"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:text="@{item.body}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/ivAvatar"
app:layout_constraintStart_toStartOf="@id/ivAvatar"
app:layout_constraintTop_toBottomOf="@id/tvTitle"
tools:text="Sample Body" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>