epoxy: EpoxyAttribute generate problem for Kotlin

I try to apply EpoxyAttribute to field in Kotlin, like below:

@EpoxyModelClass(layout = R.layout.model_epoxy)
abstract class TestEpoxyModel(@EpoxyAttribute @ColorInt var color: Int) : EpoxyModel<View>() {
	override fun bind(view: View?) {
		view?.setBackgroundColor(color)
	}
}

And got error on compile annotation, like below:

com.airbnb.epoxy.EpoxyProcessorException: EpoxyAttribute annotations must not be on private or static fields. (class: TestEpoxyModel, field: color)
e: Some error(s) occurred while processing annotations. Please see the error messages above.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (12 by maintainers)

Most upvoted comments

@elihart i solved it. change annotationProcessor 'com.airbnb.android:epoxy-processor:2.2.0' to kapt 'com.airbnb.android:epoxy-processor:2.2.0'

@minibugdev sorry, I wasn’t clear enough. It wasn’t a solution for you case - it was a proposal to @elihart how it could be possibly solved in a more kotlin way. @JvmField works as a temporary workaround tho.

The problem is that in Kotlin backing fields of properties are private which are not allowed by epoxys annotation processor.

@elihart I’ve solved the same issue in StorIO. The solution was to allow annotate not only actual fields but methods as well - getters in our case. It looks like that:

@StorIOSQLiteType(table = "tweets") data class Tweet @StorIOSQLiteCreator constructor(@get:StorIOSQLiteColumn(name = "author") val author: String,
                                                  @get:StorIOSQLiteColumn(name = "content") val content: String)

I am not sure that it is the best solution, but it was at least the easiest one to integrate into current codebase. As a bonus it also allows to use annotation on AutoValue classes since they can be used on methods.