AndroidAnnotations version: 4.3.1
Android compile SDK version: 26
Kotlin version: 1.1.3-2
I am trying to build app using Kotlin and AndroidAnnotaions. The build ends with
Error:Execution failed for task ':app:kaptDebugKotlin'. > Internal compiler error. See log for more details
00:10:43.908 [RMI TCP Connection(91)-127.0.0.1] ERROR o.a.i.p.ModelValidator:77 - org.androidannotations.annotations.ViewById cannot be used on a private element
var description: TextView? = null
Try to use
@ViewById lateinit var description: TextView
The reason of getting this error may because of the behavior of the backing field. It is private by default and the
field identifier can only be used in the accessors of the property. That's why you got
@ViewById cannot be used on a private element.
The reason of why
lateinit works is because it change the accessibility of the field. According to Kotlin doc:
Late-Initialized properties are also exposed as fields. The visibility of the field will be the same as the visibility of lateinit property setter.
@JvmField is another solution for this problem.
@JvmField var helloTextView: TextView? = null
It also changes the visibility of the field as what the doc states:
If you need to expose a Kotlin property as a field in Java, you need to annotate it with the @JvmField annotation. The field will have the same visibility as the underlying property. You can annotate a property with @JvmField if it has a backing field, is not private, does not have open, override or const modifiers, and is not a delegated property.