Hello guys. I am trying to set up Room DB for KMM ...
# multiplatform
j
Hello guys. I am trying to set up Room DB for KMM and it works fine for the android however, when I add this dependency block
Copy code
dependencies {
    add("kspAndroid", libs.room.compiler)
    add("kspIosSimulatorArm64", libs.room.compiler)
    add("kspIosX64", libs.room.compiler)
    add("kspIosArm64", libs.room.compiler)
}
add("kspAndroid", libs.room.compiler)
works fine but when I add the the last three it and attempt to sync gradle, I get this error
A problem occurred configuring project ':composeApp'. Cannot change attributes of configuration ':composeApp:debugFrameworkIosX64' after it has been locked for mutation
Furthermore, when replace the block above with this
Copy code
dependencies {
    add("kspAndroid", libs.room.compiler)
    afterEvaluate {
        add("kspIosSimulatorArm64", libs.room.compiler)
        add("kspIosX64", libs.room.compiler)
        add("kspIosArm64", libs.room.compiler)
    }
}
gradle sync works but iosMain Data base configuration doesn't generate. This is the ios Database config function
Copy code
private fun getDatabase(): PropertyDatabase {
    val dbFile = NSHomeDirectory() + "/property.db"

    return Room.databaseBuilder<PropertyDatabase>(
        name = dbFile,
        factory = { PropertyDatabase::class.instantiateImpl() }
    ).setDriver(BundledSQLiteDriver())
        .fallbackToDestructiveMigration(false)
        .build()
}
PropertyDatabase::class.instantiateImpl()
line shows an error when I try to rebuild because the instantiateImpl() is not generating `
e
Hi Joe, please check this repo: https://github.com/cvivek07/KMM-PicSplash
j
Thanks alot. I was able to run gradle build however, When I run the app, I get this error
Class 'PropertyDatabase_Impl' is not abstract and does not implement abstract base class member 'clearAllTables'.
e
check database class in that repo
there is a trick you have to implement
j
Yea. I saw what you did there. Thanks a lot. You just save me from my confusion.
I really appreciate
e
you're welcome
🙌 1
f
hi @Joe Altidore, I apologise to call you out after 2 months since this thread... I was hoping to ask you how you managed to generate the Database implementations for iOS...
I see you use afterEvaluate, which make gradle build successfully, but I'm unable to see the actual ksp tasks when doing
Copy code
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
    if (name != KSP_TASK_NAME ) {
        dependsOn(KSP_TASK_NAME)
    }
}
j
Hello @Fabio Santo I was able to resolve it through the help of @Emirhan Emmez. Kindly check out This repo for the steps.
f
ah yes thank you, I did check that, but he uses commonMain as sourceSet to which ksp easily creates ksp tasks... I can't because my commonMain supports JS as well, which unfortunately is not supported by room 😄
j
Oh! I had to revert back to is approach for my use case and it worked for me
f
I see, I thought so 👍 okay then thank you anyway
1725 Views