InsertKoinIO / koin-annotations

Koin Annotations - About Koin - a pragmatic lightweight dependency injection framework for Kotlin & Kotlin Multiplatform insert-koin.io
https://insert-koin.io
Apache License 2.0
163 stars 44 forks source link

Expected class 'expect class DatabasePlatformModule : Any' does not have default constructor. #183

Open yet300 opened 3 weeks ago

yet300 commented 3 weeks ago

I am writing a new project on kmp using koin annotation and room kmp and I get an error when building the project.

e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/android/androidDebug/kotlin/ru/hadj/database/db/SkillingoRoomDatabaseConstructor.kt:5:22 'actual object SkillingoRoomDatabaseConstructor : RoomDatabaseConstructor<SkillingpRoomDatabase>' has no corresponding expected declaration
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/android/androidDebug/kotlin/ru/hadj/database/db/SkillingoRoomDatabaseConstructor.kt:7:23 'actual fun initialize(): SkillingpRoomDatabase' has no corresponding expected declaration
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/metadata/commonMain/kotlin/org/koin/ksp/generated/DataBaseModuleGenru$hadj$database$di.kt:8:31 Expected class 'expect class DatabasePlatformModule : Any' does not have default constructor.
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/metadata/commonMain/kotlin/ru/hadj/database/dao/BoostDao_Impl.kt:25:14 Redeclaration:
class BoostDao_Impl : BoostDao
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/metadata/commonMain/kotlin/ru/hadj/database/dao/TaskDao_Impl.kt:24:14 Redeclaration:
class TaskDao_Impl : TaskDao
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/metadata/commonMain/kotlin/ru/hadj/database/dao/TaskGroupDao_Impl.kt:22:14 Redeclaration:
class TaskGroupDao_Impl : TaskGroupDao
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/metadata/commonMain/kotlin/ru/hadj/database/db/SkillingoRoomDatabaseConstructor.kt:5:22 'actual object SkillingoRoomDatabaseConstructor : RoomDatabaseConstructor<SkillingpRoomDatabase>' has no corresponding expected declaration
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/metadata/commonMain/kotlin/ru/hadj/database/db/SkillingoRoomDatabaseConstructor.kt:5:22 Redeclaration:
actual object SkillingoRoomDatabaseConstructor : RoomDatabaseConstructor<SkillingpRoomDatabase>
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/metadata/commonMain/kotlin/ru/hadj/database/db/SkillingoRoomDatabaseConstructor.kt:7:23 'actual fun initialize(): SkillingpRoomDatabase' has no corresponding expected declaration
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/metadata/commonMain/kotlin/ru/hadj/database/db/SkillingpRoomDatabase_Impl.kt:33:8 Class 'SkillingpRoomDatabase_Impl' is not abstract and does not implement abstract base class member 'clearAllTables'.
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/build/generated/ksp/metadata/commonMain/kotlin/ru/hadj/database/db/SkillingpRoomDatabase_Impl.kt:33:14 Redeclaration:
class SkillingpRoomDatabase_Impl : SkillingpRoomDatabase
e: file:///Users/Shared/development/Multiplatform/Skillingo/core/database/src/androidMain/kotlin/ru/hadj/database/db/getDataBaseBuilder.android.kt:10:14 'actual class DataBasePlatform : Any' has no corresponding members for expected class members:

    expect constructor(): DataBasePlatform

    The following declaration is incompatible because number of value parameters is different:
        constructor(context: Context): DataBasePlatform

> Task :core:database:copyRoomSchemas

DataBase Module: *db package

class SkillingoDatabase internal constructor(private val database: SkillingpRoomDatabase) {
    val taskDao: TaskDao
        get() = database.taskDao()
    val taskGroupDao: TaskGroupDao
        get() = database.taskGroupDao()
    val boostDao: BoostDao
        get() = database.boostDao()
}

@Database(
    entities = [TaskDBO::class, TaskGroupDBO::class, BoostModeDBO::class],
    version = 1
)
@TypeConverters(Converters::class)
@ConstructedBy(SkillingoRoomDatabaseConstructor::class)
abstract class SkillingpRoomDatabase : RoomDatabase() {
    abstract fun taskDao(): TaskDao

    abstract fun taskGroupDao(): TaskGroupDao

    abstract fun boostDao(): BoostDao
}

internal const val dbFileName = "skillingo_db"

@Single
fun SkillingoDatabase(
    @Provided databaseBuilder: RoomDatabase.Builder<SkillingpRoomDatabase>,
): SkillingoDatabase {
    return SkillingoDatabase(
        databaseBuilder
            .setQueryCoroutineContext(Dispatchers.IO)
            .fallbackToDestructiveMigration(dropAllTables = false)
            .build()
    )
}

// The Room compiler generates the `actual` implementations.
@Suppress("NO_ACTUAL_FOR_EXPECT")
expect object SkillingoRoomDatabaseConstructor : RoomDatabaseConstructor<SkillingpRoomDatabase> {
    override fun initialize(): SkillingpRoomDatabase
}

package ru.hadj.database.db

expect class DataBasePlatform(){
    fun getDataBaseBuilder() : RoomDatabase.Builder<SkillingpRoomDatabase>
}

package ru.hadj.database.di
@Module(includes = [DatabasePlatformModule::class])
@ComponentScan
class DataBaseModule

@Module
expect class DatabasePlatformModule

**androidMain**
package ru.hadj.database.db

@Factory
actual class DataBasePlatform(private val context: Context) {
    actual fun getDataBaseBuilder(): RoomDatabase.Builder<SkillingpRoomDatabase> {
        return Room.databaseBuilder(
            context = context,
            klass = SkillingpRoomDatabase::class.java,
            name = "skiliingo"
        )
    }
}
package ru.hadj.database.di

@Module
@ComponentScan("ru.hadj.database.db")
actual class DatabasePlatformModule

Koin project used and used version: [koin-core version 4.0.0] [koin-annotation version 1.4.0]

Other: [room version 2.7.0-alpha10] [ksp version 2.0.20-1.0.25] [sqlite version 2.5.0-SNAPSHOT]