Search code examples
android-fragmentskotlinandroid-annotations

How to use AndroidAnnotation @FragmentArg with Kotlin?


How can I use @FragmentArg from AndroidAnnotations within Kotlin fragment?

@EFragment(R.layout.debug_empty_fragment)
open class EmptyFragment : Fragment(){

    @FragmentArg("debugIndex")
    var debugIndex:Int = 0
}

This gives me following gradle error:

error: org.androidannotations.annotations.FragmentArg cannot be used on a private element

I tried making debugIndex open (public), but it is not working. Any ideas? Is this even possible?

I`m using Android Annotations 4.3.1 and kotlin 1.1.2-5


Solution

  • Okay, @JvmField is your friend. (further information)

    Instructs the Kotlin compiler not to generate getters/setters for this property and expose it as a field.

    So @FragmentArg should look like this

    @JvmField
    @FragmentArg("debugIndex")
    var debugIndex:Int = 0