Skip to content

KSP with builtin Kotlin cannot resolve R file #2857

@jonamireh

Description

@jonamireh

Summary

Given a build with KSP 2.3.6 and an Android Application or Library with AGP9 & built-in Kotlin, KSP processors using validate will not able to process symbols that involve the generated R file unless the explicit type is declared

I've attached a project with a sample processor MyAnnotationProcessor for @MyAnnotation that records the symbols processed & the symbols that were deferred after all rounds. I then declared the following in the Android :app module, where R.string.sample_label is an existing Android String resource:

@MyAnnotation
class SampleAnnotatedClass(
    val name: String,
) {
    val labelRes = R.string.sample_label
}

With builtin Kotlin, MyAnnotationProcessor will defer SampleAnnotatedClass every round because it cannot resolve the type of labelRes. However, if you compile the project without builtin Kotlin & apply kotlin-android instead, it immediately is able to process SampleAnnotatedClass

ksp-agp9-bug.zip

$ ./gradlew :app:kspDebugKotlin --warn --rerun-tasks
w: [ksp] MyAnnotation processor finish deferred symbols: SampleAnnotatedClass

$ ./gradlew :app:kspDebugKotlin --warn --rerun-tasks -Pandroid.builtInKotlin=false -Pandroid.newDsl=false
w: [ksp] MyAnnotation processor saw class: dev.jonamireh.ksp_agp9.SampleAnnotatedClass with declarations: name, labelRes, <init>
w: [ksp] MyAnnotation processor finish deferred symbols: <empty>

Related: #2748

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3desirable

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions