DeepLinkDispatch
DeepLinkDispatch copied to clipboard
Custom annotations not working in Kotlin
I'm trying to use custom annotations on top-level methods in Kotlin. Unfortunately, they don't work. No DeepLinkEntry
s are generated for them. Only if I annotate at least one static method in a Java class too the correct DeepLinkEntry
s 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)
}
is there any updates regarding this? how did you solve it @joluet
@ghiyatshanif make sure the method is in an object
then annotate it with the @JvmStatic
annotation
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)
}
}