【问题标题】:Why Epoxy does not generate model class?为什么 Epoxy 不生成模型类?
【发布时间】:2018-07-21 16:50:59
【问题描述】:

我想用 Epoxy 为我的 recyclerView 使用 kotlin,但是 Epoxy Model 没有生成 PostModel_() 类,有什么问题?

@EpoxyModelClass(layout = R.layout.iteam)
abstract class PostModel : EpoxyModelWithHolder<PostModel.PostHolder>() {
  @EpoxyAttribute
  lateinit var userName: String
  @EpoxyAttribute
  lateinit var avatarIcon: Drawable
  @EpoxyAttribute
  lateinit var post: Drawable

  override fun bind(holder: PostHolder) {
    holder.avatarIcon.setImageDrawable(avatarIcon)
    holder.post.setImageDrawable(post)
    holder.name.text = userName

  }

  class PostHolder : BaseEpoxyHolder() {
    @BindView(R.id.name)
    lateinit var name: TextView
    @BindView(R.id.ic_avatar)
    lateinit var avatarIcon: ImageView
    @BindView(R.id.post)
    lateinit var post: ImageView
  }

}

【问题讨论】:

  • 你添加apply plugin: 'kotlin-kapt'了吗?
  • 是的,我有这条线
  • 你是如何声明依赖关系的?
  • 您解决了这个问题吗?我现在也面临同样的问题。-@manwhotrycoding

标签: java android kotlin epoxy epoxy-modelview


【解决方案1】:

在 Kotlin 中使用 Epoxy 时的一个常见错误是混合注释处理引擎。如果你从 Epoxy 的自述文件中复制了这个:

dependencies {
  implementation 'com.airbnb.android:epoxy:3.x.y'
  // Add the annotation processor if you are using Epoxy's annotations (recommended)
  annotationProcessor 'com.airbnb.android:epoxy-processor:3.x.y'
}

您可能忘记在同一个自述文件的几行后面应用他们对 kotlin 用户的建议:

确保使用kapt 而不是annotationProcessor

【讨论】:

    【解决方案2】:

    我错误地从我的模型文件中删除了第一行:

    package com.myCustomDomain.myapp.epoxyModel
    

    所以自动生成的文件是用错误的文件名生成的。

    【讨论】:

      猜你喜欢
      • 2020-04-04
      • 2020-06-24
      • 1970-01-01
      • 1970-01-01
      • 2014-04-25
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多