It is throws an exception like this `Only static m...
# android
b
It is throws an exception like this
Only static methods can be annotated with @DeepLink
g
@budioktaviyan Please, show your code. Probably you annotated class method with this annotation.
Try to annotate top level function or move function to companion object and add
@JvmStatic
annotation
b
Copy code
@DeepLink(SCHEME.plus(SERVICE_PAYMENT))
fun registerServiceDeepLink(context: Context): Intent {}
g
Please show more code, it’s just a function declaration
b
I just create this in my class, but suddenly it throws the exception. Previously it was Java class with static function
g
As I said, if you need static method, you have two options, I mentioned them above
Kotlin has no static function, you should use top level function (function outside class) or function inside companion object with
@JvmStatic
annotation
b
Yes, I ever do that but it is not working
wait, I will share the complete code
Copy code
class DeepLinkDispatcher {

    companion object {
        const val SERVICE_PAYMENT = "payment"
        const val SCHEME = "myweb://"
        const val FLAGS_NEW_TASK = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP

        @DeepLink(SCHEME.plus(SERVICE_PAYMENT))
        @JvmStatic
        fun registerServiceDeepLink(context: Context): Intent {
            return Intent(context, clazz<PaymentHomeActivity>()).apply {
                putExtra(PaymentHomeActivity.HomeIntentKey.SOURCE, MyConstants.EventConstants.PROPERTY_VALUE_SOURCE_DEEP_LINK)
                action = DeepLinkKey.ACTION_DEEP_LINK_SERVICE
                flags = FLAGS_NEW_TASK
            }
        }
    }
}
g
Oh, yeah, I see, probably it will not work, just because JvmStatic generates one more method, not replaced original one. Maybe better to use top level function
b
I have been do this but it is not working for this lib 😄
hmmm ic
g
I’m not sure about my previous statement, but probably it works this way
b
let me try
g
Anyway, top level functions is definetely static
b
yeah, I know it :) .. cool its working now
g
I’ve checked. Yes, @JvmStatic creates one more method for Java, that proxies call to Companion object, so this lib found also non-static version
Actually it’s interesting case, maybe you should create an issue about it, and someone would propose some solution also for such cases, but probably top level function is good workaround for all cases, I’m not sure
b
yes, I will raised an issue on those lib ASAP 🙂
g
Anyway, this lib does everything in correct way, but probably they could add some Kotlin workaround and docs
b
and did you know ? this lib are really helpfull for create a simple deeplink in android hahaha
a
This would make a great medium post, exploring the compile-time differences between @JVMStatic annotated methods and top-level methods.. because I can guarantee other people will be bitten by this (I learned something today!)
b
Yes, me too, Just know it. Sometimes it can be a little bit different between top-level function and
@JVMStatic
hahahha