![](/img/trans.png)
[英]Android Studio Library Projects (Modules) show up as different Build Variants
[英]EpoxyModels are not working in feature modules/library projects in Android
使用 Android 應用程序的內部功能模塊時,EpoxyModels 未編譯。
@EpoxyModelClass(layout = R.layout.layout_foo) //an annotation argument must be a compile-time constant here
abstract class FooModel : EpoxyModelWithHolder<FooModel.FooHolder>()
{
...
...
class FooHolder : BaseEpoxyHolder()
{
val textViewTitle: TextView by bind((R.id.textViewTitle))
//bind is the method borrowed from [here](https://github.com/airbnb/epoxy/blob/963ef0fd850bd379da7b0be6a2ada25d01ae0ee7/kotlinsample/src/main/java/com/airbnb/epoxy/kotlinsample/helpers/KotlinEpoxyHolder.kt#L20)
}
}
上面的代碼抱怨 layout = R.layout.layout_foo 行的“an annotation argument must be a compile-time constant”。
再次基於文檔看起來,butterknife 需要用於庫項目(功能模塊在某種程度上是一種庫項目),它將基於此生成 R2 類
下面是使用 Butterknife 修改后的代碼,我也認為它太過分了。 不確定,為什么我不能只做 findviewbyId。
ModelClass(layout = R2.layout.layout_foo)
abstract class FooModel : EpoxyModelWithHolder<FooModel.FooHolder>() {
@EpoxyAttribute
lateinit var fooDto: Foo
override fun bind(holder: FooHolder) {
holder.textViewTitle.text = fooDto.title
}
class FooHolder : BaseEpoxyHolder() {
@BindView(R2.id.textViewTitle) lateinit var textViewTitle: TextView
}
}
下面是來自帶有 butterknife 的 viewholder 的錯誤
kotlin.UninitializedPropertyAccessException:lateinit 屬性 textViewTitle 尚未初始化
正如所說:
https://github.com/airbnb/epoxy/issues/819#issuecomment-576728923
在庫項目上使用該注釋存在問題。
目前你可以使用:
@EpoxyModelClass
abstract class MyModel : EpoxyModelWithHolder<MyHolder>() {
override fun getDefaultLayout(): Int {
return R.layout.my_layout
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.