2

I've a KMP shared module that imports a KSP library to generate code for iOS targets, and it works as expected:

enter image description here

However, I’m facing a strange behavior; my generated code cannot see/access what’s in iosMain (generated code imports classes from iosMain).

My configuration:

val iosMain by creating {
    dependsOn(commonMain)
    dependencies {
        // ...
    }
}

listOf(iosX64, iosArm64, iosSimulatorArm64).forEach { target ->
    getByName("${target.targetName}Main") {
        dependsOn(iosMain)
    }

    val kspConfigName = "ksp${target.name.replaceFirstChar { it.uppercaseChar() }}"
    dependencies.add(kspConfigName, "my-ksp-lib")
}

What am I doing wrong or missing?

1 Answer 1

1

By default, IntelliJ IDEA or other IDEs don't know about the generated code. So it will mark references to generated symbols unresolvable. To make an IDE be able to reason about the generated symbols, mark the following paths as generated source roots:

all {       
    kotlin.srcDir("build/generated/ksp/${target.targetName}/${target.targetName}Main/kotlin")
}

More information about it here in kotlinlang docs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.