使用Android App的内部功能模块时,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行的“注释参数必须是编译时常量”。
再次基于文档,黄油刀需要用于将基于this生成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 } }
下面是来自错误查看器和黄油刀的错误>>
kotlin.UninitializedPropertyAccessException:lateinit属性textViewTitle尚未初始化
感谢您的帮助。
EpoxyModels在使用Android App的内部功能模块时未编译。 @EpoxyModelClass(layout = R.layout.layout_foo)//注解参数必须是编译时常量,这里abstract ...