我有一个多模块项目,其中应用程序模块包含我的绑定适配器,而我的功能模块取决于我的应用程序模块,因为它是动态功能模块。
应用程序(包含绑定适配器)---->动态功能模块(存在布局的地方)
我在所有模块中启用了数据绑定和 kapt。
我无法成功构建应用程序。 Android Studio 给我以下错误,
error: cannot find symbol
import com.app.module1.databinding.FeatureItemBindingImpl;
动态功能模块中的布局文件:
<?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>
App模块中绑定Adapter:
@BindingAdapter("set_image")
fun AppCompatImageView.setImageToImageView(@DrawableRes drawable: Int) {
this.setImageResource(drawable)
}
我遇到了同样的问题,因为我试图访问其他模块中的类。当我将尝试访问的类放入包含 xml 的模块时,它就修复了。您只能从 XML 中访问该模块中的类。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)