Hi there, I am working through the integration of...
# room
c
Hi there, I am working through the integration of Room KMP into a project. The Android side was very straightforward and easy to get running. However, when I tried to run the iOS app, I encountered build errors. I am following the documentation and using Room version 2.7.0-alpha04. Wondering if anyone has seem something similar? Here are the error messages I’m seeing:
Copy code
> Task :shared:generateNonAndroidBuildConfig UP-TO-DATE

> Task :shared:kspKotlinIosArm64
i: [ksp] loaded provider(s): [androidx.room.RoomKspProcessor$Provider]

> Task :shared:kspKotlinIosSimulatorArm64
i: [ksp] loaded provider(s): [androidx.room.RoomKspProcessor$Provider]

> Task :shared:copyRoomSchemas NO-SOURCE

> Task :shared:compileKotlinIosSimulatorArm64
e: file:///Users/..../newm-mobile/shared/src/iosMain/kotlin/database/GetNewmRoomDatabaseBuilder.ios.kt:13:20 Type mismatch: inferred type is Unit but RoomDatabase was expected
e: file:///Users/....//newm-mobile/shared/src/iosMain/kotlin/database/GetNewmRoomDatabaseBuilder.ios.kt:13:20 Type mismatch: inferred type is Unit but NewmAppDatabase was expected
e: file:///Users/....//newm-mobile/shared/src/iosMain/kotlin/database/GetNewmRoomDatabaseBuilder.ios.kt:13:45 Unresolved reference: instantiateImpl

> Task :shared:compileKotlinIosSimulatorArm64 FAILED

> Task :shared:compileKotlinIosArm64 FAILED
e: file:///Users/..../newm-mobile/shared/src/iosMain/kotlin/database/GetNewmRoomDatabaseBuilder.ios.kt:13:20 Type mismatch: inferred type is Unit but RoomDatabase was expected
e: file:///Users/..../newm-mobile/shared/src/iosMain/kotlin/database/GetNewmRoomDatabaseBuilder.ios.kt:13:20 Type mismatch: inferred type is Unit but NewmAppDatabase was expected
e: file:///Users/..../newm-mobile/shared/src/iosMain/kotlin/database/GetNewmRoomDatabaseBuilder.ios.kt:13:45 Unresolved reference: instantiateImpl

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
// shared/src/androidMain/kotlin/Database.k
Copy code
fun getRoomDatabaseBuilder(context: Context): RoomDatabase.Builder<NewmAppDatabase> {
  val dbFile = context.getDatabasePath("newm-app.db")
  return Room.databaseBuilder<NewmAppDatabase>(
    context = context,
    name = dbFile.absolutePath
  )
}
// shared/src/iosMain/kotlin/Database.kt
Copy code
fun getNewmAppDatabase(): RoomDatabase.Builder<NewmAppDatabase> {
  val dbFile = NSHomeDirectory() + "/newm-app.db"
  return Room.databaseBuilder<NewmAppDatabase>(
    name = dbFile,
    factory = { NewmAppDatabase::class.instantiateImpl() }
  )
}
// shared/src/commonMain/kotlin/Database.kt
Copy code
fun getNewmAppDatabase(
  builder: RoomDatabase.Builder<NewmAppDatabase>
): NewmAppDatabase {
  return builder
    .fallbackToDestructiveMigrationOnDowngrade(dropAllTables = true)
    .setDriver(BundledSQLiteDriver())
    .setQueryCoroutineContext(Dispatchers.IO)
    .build()
}
234 Views