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)
@elihart i solved it. change
annotationProcessor 'com.airbnb.android:epoxy-processor:2.2.0'
tokapt '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:
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.