Solution 1 :
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.
Problem :
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)
}
Comments
Comment posted by chrisdottel
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.
Comment posted by Jitendra Reddy
@AnonAnonym updated the post
Comment posted by Jitendra Reddy
@AnonAnonym I tired cleaning build and caches but it didn’t work
Comment posted by stackoverflow.com/questions/63176547/…
Hi, this is possible duplicate to