airbnb / DeepLinkDispatch

A simple, annotation-based library for making deep link handling better on Android
http://nerds.airbnb.com/deeplinkdispatch/
4.37k stars 409 forks source link

Custom Annotations not working after update to v6.1.0 #362

Open arpank10 opened 1 year ago

arpank10 commented 1 year ago

Updated Version : v6.1.0 Previous Version: v5.4.3

Annotation processor used: kapt

We have custom annotations to register deep links, they are defined like this:

@DeepLinkSpec(prefix = ["xyz://"])
annotation class AppDeepLink(vararg val value: String)

The functions are defined as follows:

@AppDeepLink(abc)
@WebDeepLink(abc)
 public static Intent registerDeepLink(Context context, Bundle bundle) {
        / * Deep Link handling */
        return intent;
}

The custom annotations were working fine with version 5.4.3, but they are not generated in the Registry with the new version.

Note: We have tried adding Retention(AnnotationRuntime.RUNTIME) to our custom annotation The custom annotations are also added to our build.gradle and incremental processing is enabled.

jramism commented 6 months ago

I am facing a similar problem, ksp saying all the time the error "Prefix property cannot be empty". I set the prefix and checked everything hundred of times and nothing

jramism commented 6 months ago

Needed some time to reach what was happening but I found the reason of my problem. Seems that android BuildConfig variables are not supported in the DeepLink annotations because of a KSP limitation. I was using them as the root domain and then the processor was ignoring them like i wasn't set a value.

prefix = [ "https://" + BuildConfig.API_URL ] -> Doesn't work (handles it as empty string) prefix = [ "https://example.com" ] -> Works

I worked on a workaround until google fixes ksp. Hope it helps if someone has the same problem. You need to put it in gradle.build, inside android section.


androidComponents {
        onVariants(selector().all(), { variant ->
            afterEvaluate {
                def variantName = variant.name.capitalize()
                def kspKotlinTaskName = "ksp${variantName}Kotlin"
                project.tasks.named(kspKotlinTaskName) { kspKotlinTask ->
                    def genBuildConfigTaskName = "generate${variantName}BuildConfig"
                    def genBuildConfigTask = project.tasks.named(genBuildConfigTaskName).get()
                    kspKotlinTask.setSource(
                        genBuildConfigTask.sourceOutputDir
                    )
                }
            }
        })
    }