DeepLinkDispatch icon indicating copy to clipboard operation
DeepLinkDispatch copied to clipboard

Custom annotations not working in Kotlin

Open joluet opened this issue 7 years ago • 3 comments

I'm trying to use custom annotations on top-level methods in Kotlin. Unfortunately, they don't work. No DeepLinkEntrys are generated for them. Only if I annotate at least one static method in a Java class too the correct DeepLinkEntrys are generated.

My custom annotation looks like this:

@DeepLinkSpec(prefix = arrayOf("http://myapp.com", "https://myapp.com", "myapp://"))
annotation class WebAndAppLink(vararg val value: String)

and the annotated top-level method looks like this:

@WebAndAppLink("/main")
fun main(context: Context): Intent {
    return MainActivity.getIntent(context)
}

joluet avatar Oct 09 '17 08:10 joluet

is there any updates regarding this? how did you solve it @joluet

ghiyatshanif avatar Oct 07 '19 12:10 ghiyatshanif

@ghiyatshanif make sure the method is in an object then annotate it with the @JvmStatic annotation

matthewrkula avatar Oct 17 '19 23:10 matthewrkula

It works on kotlin with our project. You have to annotate your annotation class with @Retention(AnnotationRetention.RUNTIME) and then create an object like this:

 object DeeplinkIntents {
        @JvmStatic
        @CustomDeeplink("/view/{extraId}")
        fun intentForDeepLinkMethod(context: Context): TaskStackBuilder {
            return buildTaskStackForDeeplink(context, MyActivity::class.java)
        }
}

carvaq avatar Dec 10 '19 12:12 carvaq