Hey everyone, I was wondering, does anyone have a ...
# koin
l
Hey everyone, I was wondering, does anyone have a proper setup for KMP koin setup with multi-module component scan? Because no matter what I try, it still does not resolve in original module
d
Check into how you start koin, and how you declare your modules
l
I checked, ksp did not generate the proper declarations. It's perhaps because of ksp2
d
I had problems with this piece of config in: build.gradle.kts (shared module) (I use koin also on server module)
Copy code
dependencies {
    implementation(project.dependencies.platform(libs.koin.annotations.bom))
    add("kspCommonMainMetadata", libs.koin.ksp.compiler)
    add("kspAndroid", libs.koin.ksp.compiler)
    add("kspIosX64", libs.koin.ksp.compiler)
    add("kspIosArm64", libs.koin.ksp.compiler)
    add("kspIosSimulatorArm64", libs.koin.ksp.compiler)
}
Even now I'm not sure it was the right thing to do, but it works and I don't touch it
I don't use Koin Annotations at all though, only the explicit API/ code
If it's KMP, you need to start koin on all platform separately, not from the common code. It took me a while to resolve modules as well
For android I start like this:
Copy code
@Composable
fun Application(activity: MainActivity) {
    KoinApplication(application = {
        androidContext(activity)
        modules(androidModule())
    }) {
        App()
    }
}
iOS:
Copy code
@Suppress("unused")
fun MainViewController() = run {
    ComposeUIViewController {
        KoinApplication(application = {
            modules(composeModule)
        }) {
            App()
        }
    }
}
Desktop:
Copy code
fun main() {
    application {
        KoinApplication(application = {
            modules(desktopModule)
        }) {
            Window(
                onCloseRequest = ::exitApplication,
                title = "App name",
                state = rememberWindowState(
                    size = DpSize(800.dp, 600.dp)
                )
            ) {
                App()
            }
        }
    }
}
l
Yeah, I don't have issues with koin itself, just that its KSP processor for annotations does not see classes in other modules
a
@Lukas Anda still have issues in KMP multimodule?
l
I updated to latest libraries too
@arnaud.giuliani
a
ok, need to check (and have time to check) 🙂
l
Amazing, please lmk. I can make you contributor to the project if you want or a nice working sample would be even nicer
👍 1
@arnaud.giuliani Hey there, any progress perhaps on this? I tried even with latest Annotations 2.3.0, ksp 2.3.0 and Kotlin 2.3.0-Beta1 and it still doesn't work