can't use room in KMP desktop project, after follo...
# multiplatform
p
can't use room in KMP desktop project, after following this guide: https://funkymuse.dev/posts/kmp-room-setup/ it gives me this error when compiling:
AppDatabaseConstructor.kt:5:22 'actual object AppDatabaseConstructor : RoomDatabaseConstructor<BusStopsDatabase>' has no corresponding expected declaration
I'm adding the gradle file in a thread here
this is my gradle file:
Copy code
plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.composeMultiplatform)
    alias(libs.plugins.composeCompiler)

    // Room
    alias(libs.plugins.androidx.room)
    alias(libs.plugins.ksp)
}

kotlin {
    jvm("desktop")
    
    sourceSets {
        val desktopMain by getting
        
        commonMain.dependencies {
            implementation(compose.runtime)
            implementation(compose.foundation)
            implementation(compose.material)
            implementation(compose.ui)
            implementation(compose.components.resources)
            implementation(compose.components.uiToolingPreview)
            implementation(libs.androidx.lifecycle.viewmodel)
            implementation(libs.androidx.lifecycle.runtime.compose)

            //koin
            implementation(project.dependencies.platform(libs.koin.bom))
            implementation(libs.koin.core)
            implementation(libs.koin.compose)
            implementation(libs.koin.compose.viewmodel.navigation)

            //retrofit
            implementation("com.squareup.retrofit2:retrofit:2.11.0")
            implementation("com.squareup.retrofit2:converter-jackson:2.11.0")
            implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.2")
            implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.0")

            //room
            implementation(libs.androidx.sqlite.bundled)
            implementation(libs.androidx.room.runtime)
        }
        desktopMain.dependencies {
            implementation(compose.desktop.currentOs)
            implementation(libs.kotlinx.coroutines.swing)
        }
    }
}

dependencies {
    add("kspDesktop", libs.androidx.room.compiler)
}

room {
    schemaDirectory("$projectDir/schemas")
}

compose.desktop {
    application {
        mainClass = "com.package.MainKt"

        nativeDistributions {
            targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
            packageName = "com.package"
            packageVersion = "1.0.0"
        }
    }
}
s
i think maybe you need to suppress this error..this is my db impl:
Copy code
@ConstructedBy(FooDatabaseConstructor::class)
abstract class FooDatabase : RoomDatabase() {}

@Suppress("NO_ACTUAL_FOR_EXPECT")
expect object FooDatabaseConstructor : RoomDatabaseConstructor<FooDatabase> {
    override fun initialize(): FooDatabase
}
I don't remember where I learned this but hopefully it works for you
p
I already have it, so it's not the cause:
Copy code
@Database(entities = [BusStopEntity::class], version = 1)
@ConstructedBy(AppDatabaseConstructor::class)
abstract class BusStopsDatabase : RoomDatabase() {
    abstract fun busStopDao(): BusStopsDao
}

// The Room compiler generates the `actual` implementations.
@Suppress("NO_ACTUAL_FOR_EXPECT")
expect object AppDatabaseConstructor : RoomDatabaseConstructor<BusStopsDatabase> {
    override fun initialize(): BusStopsDatabase
}
s
oh i see. so you haven't created any
actual
declarations? the error is pointing to a file in the build folder?
p
sorry I don't understand you
the error is in an autogenerated file, if you mean that
the error is here:
Copy code
public actual object AppDatabaseConstructor : RoomDatabaseConstructor<BusStopsDatabase> {
  actual override fun initialize(): BusStopsDatabase =
      com.mypackage.`data`.datasource.local.BusStopsDatabase_Impl()
}
I didn't created that
s
ok yeah that's what i was trying to ask. hm idk...I haven't really done much with my desktop app so I haven't fully verified that I have everything set up right and running but it seems to be building ok and I assumed it was pretty much gtg. i'll try to double check soon whether my app is running and working.
p
maybe it's because I'm creating the datasource, repositories etc... on desktopMain?
maybe it needs to be done in commonMain?
s
the
expect object AppDatabaseConstructor : RoomDatabaseConstructor<BusStopsDatabase> { }
should be in common main for sure. I doubt repos or datasources are doing anything
p
mmmm
s
all the
abstract class BusStopsDatabase : RoomDatabase() {
stuff should be in commonMain
p
should my entire data package be in commonMain?
and just the ui on the desktopMain?
s
idk what you have in your source files and how you're organizing stuff but i guess put whatever you can in common main. I have a database module that I add as a dependency to my various apps
i have most of my ui in common shared modules/sources too.
p
where can I read how to separate my project between commonMain and desktopMain?
where should I put each thing and how to communicate them?
well, this is very complex
I'm tryint it, but without help or a guide is not possible
s
so you should have things set up for it already based on the gradle file you posted:
Copy code
sourceSets {
        val desktopMain by getting
        
        commonMain.dependencies {}
...
}
then in your src folder you can add a
commonMain
folder for common kotlin sources and a
desktopMain
for the desktop specific files. the desktop source files will be able to see the stuff in the common sources
definitely check out the official docs and watch/read tutorials to try and piece stuff together. asking for help isn't a bad thing