Hello, I need some help with Koin Annotations setu...
# koin
c
Hello, I need some help with Koin Annotations setup on AGP 9+. I use
Copy code
kotlin = "2.3.10"
ksp = "2.3.2"
koin-core = "4.2.1"
koin-annotations = "4.2.1"
koin-ksp-compiler = "2.3.1"

koin-annotations = { group = "io.insert-koin", name = "koin-annotations", version.ref = "koin-annotations" }
koin-ksp-compiler = { group = "io.insert-koin", name = "koin-ksp-compiler", version.ref = "koin-ksp-compiler" }
In my multi module setup with build config plugins. Generated ksp file for annotation.
Copy code
import org.koin.meta.annotations.*
@MetaModule("com.nymbusforge.purrtunes.core.data.di.CoreDataModule",id="9s994x", includes=["com.nymbusforge.purrtunes.core.data.di.PlatformCoreDataModule_Expect"])
public class _KSP_ComNymbusforgePurrtunesCoreDataDiCoreDataModule
Error
Copy code
e: file:///Users/chiragredij/AndroidStudioProjects/NymbusForge/PurrTunes/core/data/build/generated/ksp/metadata/commonMain/kotlin/org/koin/ksp/generated/KoinMeta-83d5a1da.kt:3:17 Unresolved reference 'meta'.
Unresolved reference 'MetaModule'. Unresolved reference 'MetaDefinition'.
There is no error during build process, it crashes when trying to run the app. What should be the correct configuration. This is the plugin file I add to my modules
Copy code
import com.google.devtools.ksp.gradle.KspExtension
import com.nymbusforge.purrtunes.convention.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.findByType
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

/**
 * Convention plugin for KSP (Kotlin Symbol Processing) annotation processing.
 *
 * This plugin:
 * - Applies the KSP Gradle plugin
 * - Configures KSP to generate code in the correct directories
 * - Sets up common KSP compiler arguments
 * - Configures KSP for all target platforms (Android, iOS)
 */
class KspConventionPlugin : Plugin<Project> {

    override fun apply(target: Project) {
        with(target) {
            // Apply the KSP Gradle plugin to enable annotation processing
            with(pluginManager) {
                apply("com.google.devtools.ksp")
            }

            // Configure KSP extension for proper code generation paths
            extensions.configure<KspExtension> {

                arg("room.schemaLocation", "$projectDir/schemas")
                arg("room.incremental", "true")
                arg("room.expandProjection", "true")

                // Set the directory where KSP will generate Kotlin source files
                // This is important for IDE integration and build caching
                arg("generateKotlin", "true")

                // Enable incremental processing for faster builds
                // KSP will only reprocess changed files
                arg("incremental", "true")

                // Generate metadata for better error messages
                arg("apoption", "ksp.incremental.log=true")
            }

            // CRITICAL FIX: Use afterEvaluate to ensure KMP plugin is configured first
            afterEvaluate {
                extensions.findByType<KotlinMultiplatformExtension>()?.apply {
                    sourceSets.named("commonMain") {
                        kotlin.srcDir("build/generated/ksp/metadata/commonMain/kotlin")
                    }
                }
            }

            // FIX: Properly declare task dependencies for all KSP tasks
            tasks.configureEach {
                if (name.startsWith("ksp") && name != "kspCommonMainKotlinMetadata") {
                    // All platform-specific KSP tasks must depend on metadata generation
                    dependsOn("kspCommonMainKotlinMetadata")
                }

                // Ensure all Kotlin compilation tasks wait for their corresponding KSP tasks
                if (name.startsWith("compileKotlin")) {
                    val kspTaskName = name.replace("compileKotlin", "ksp")
                    tasks.findByName(kspTaskName)?.let { kspTask ->
                        dependsOn(kspTask)
                    }
                }
            }

            // CRITICAL FIX: Explicitly handle KSP task dependencies
            tasks.withType<com.google.devtools.ksp.gradle.KspAATask>().configureEach {
                if (name != "kspCommonMainKotlinMetadata") {
                    // All KSP tasks must run after commonMain metadata is generated
                    mustRunAfter(tasks.named("kspCommonMainKotlinMetadata"))
                    dependsOn(tasks.named("kspCommonMainKotlinMetadata"))
                }
            }

        }
    }
}
✅ 1
t
Hey, you should use the new Koin Compiler Plugin instead of KSP which is deprecated
c
So remove KSP entirely? Or just add this new plugin to my modules?
t
Remove KSP entirely. Just read through the docs. All is explained there
c
Thank you. I will check it out. My project also uses room which needs KSP. But I will try to isolate room setup to another module if thats needed.
t
I am not entirely sure since my setup is different, but both dependencies should work together at the same time. You just need to remove the KSP setup for Koin as defined in the migration guide
f
yes, both can work together
c
Hii thank you for the guidance. I finally have the setup working on Android. There is another issue with IOS for which I am opening another thread. Thank you for the support!
👍 1