Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KMP not work #175

Open
springeye opened this issue Sep 28, 2024 · 1 comment
Open

KMP not work #175

springeye opened this issue Sep 28, 2024 · 1 comment
Labels
question Further information is requested

Comments

@springeye
Copy link

Describe the bug

To Reproduce
I followed the documentation https://insert-koin.io/docs/reference/koin-annotations/kmp configuration but it doesn't work properly

e: [ksp] --> Missing Definition type 'com.github.springeye.snote.di.DIFactory' for 'com.github.springeye.snote.di.privateAppDatabase'. Fix your configuration to define type 'DIFactory'.
e: Error occurred in KSP, check log for detail

Expected behavior
sp can build the code normally

Koin project used and used version (please complete the following information):
koin-bom = "4.0.0"
koin-annotations = "1.4.0-RC4"

// KSP Tasks
dependencies {
    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)
    add("kspDesktop",libs.koin.ksp.compiler)

    //room don‘t add kspCommonMainMetadata
//    add("kspCommonMainMetadata",libs.androidx.room.compiler)
    add("kspAndroid", libs.androidx.room.compiler)
    add("kspIosX64", libs.androidx.room.compiler)
    add("kspIosArm64", libs.androidx.room.compiler)
    add("kspIosSimulatorArm64",libs.androidx.room.compiler)
    add("kspDesktop",libs.androidx.room.compiler)


}

project.tasks.withType(KotlinCompilationTask::class.java).configureEach {
    if(name != "kspCommonMainKotlinMetadata") {
        dependsOn("kspCommonMainKotlinMetadata")
    }
}

ksp{
    arg("KOIN_CONFIG_CHECK","true")
}

commonMain/kotlin/AppModule.kt

@ComponentScan("com.github.springeye")
//@ComponentScan
@Module
class AppModule {
    @Single
    fun privateAppDatabase(factory:DIFactory):AppDatabase{
        return factory.createRoomDatabase()
    }
}

commonMain/kotlin/DIFactory.kt

expect class DIFactory {
    fun getPlatform(): Platform
    fun createRoomDatabase(): AppDatabase
}

desktopMain/kotlin/DIFactory.desktop.kt

@Single
actual class DIFactory {
    actual fun createRoomDatabase(): AppDatabase {
        return getRoomDatabase(getDatabaseBuilder())
    }

    actual fun getPlatform(): Platform {
        return JVMPlatform()
    }
}
@arnaudgiuliani
Copy link
Member

here you can't use Koin 4.0 yet with KA 1.4.0

@arnaudgiuliani arnaudgiuliani added the question Further information is requested label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants