Status Update
Comments
er...@gmail.com <er...@gmail.com> #2
[Deleted User] <[Deleted User]> #3
The actual AppDatabaseConstructor is at /MyProject/shared/storage/build/generated/ksp/android/androidDebug/kotlin/com/example/myproject/shared/storage/database/AppDatabaseConstructor.kt
and looks like this:
package com.example.myproject.shared.storage.database
import androidx.room.RoomDatabaseConstructor
public actual object AppDatabaseConstructor : RoomDatabaseConstructor<AppDatabase> {
override fun initialize(): AppDatabase =
com.example.myproject.shared.storage.database.AppDatabase_Impl()
}
Similar implementations are generated for iOS in .../iosArm64/iosArmMain64/...
, .../iosSimulatorArm64/iosSimulatorArmMain64/...
, .../iosX64/iosX64Main/...
er...@gmail.com <er...@gmail.com> #4
vi...@gmail.com <vi...@gmail.com> #5
e: file:///Users/..../kmp_project/zdckey_core/src/commonMain/kotlin/com/..../zdckey_core/data/database/ZDCKeyCoreDatabase.kt:23:8 Object 'ZDCKeyCoreDatabaseConstructor' is not abstract and does not implement abstract member 'initialize'.
e:file:///Users/..../kmp_project/zdckey_core/src/commonMain/kotlin/com/..../zdckey_core/data/database/ZDCKeyCoreDatabase.kt:23:15 ZDCKeyCoreDatabaseConstructor: expect and corresponding actual are declared in the same module
Does anyone have the solution??
da...@google.com <da...@google.com> #6
Can you please double check your build gradle configuration as mentioned here:
[Deleted User] <[Deleted User]> #7
Any other suggestions?
da...@google.com <da...@google.com> #8
Can you please provide a sample app that reproduces the issue? I'm running out of ideas without being able to check the actual project.
[Deleted User] <[Deleted User]> #9
"AppDatabaseConstructor: expect and corresponding actual are declared in the same module" does that helps maybe?
da...@google.com <da...@google.com> #10
Adding Room to the common metadata compilation (add("kspCommonMainMetadata", libs.androidx.room.ksp)
) should not be needed, only ends targets should be added as Room needs to generate code slightly different for each platform.
Have you tried using Kotlin 2.0.10
and KSP 2.0.10-1.0.24
?
[Deleted User] <[Deleted User]> #11
agp = "8.5.2"
android-compileSdk = "34"
android-minSdk = "27"
android-targetSdk = "34"
androidx-activityCompose = "1.9.1"
buildConfig = "5.4.0"
compose_activity = "1.9.1"
compose_lifecycle = "2.8.4"
compose_navigation = "2.8.0-beta06"
compose-plugin = "1.6.11"
detekt = "1.23.6"
firebase = "1.13.0"
google_services = "4.4.2"
koin_annotations = "1.3.1"
koin_bom_core = "3.5.3"
kotlin = "2.0.10"
kotlinx_collections = "0.3.7"
kotlinx_coroutines = "1.8.1"
kotlinx_datetime = "0.6.0"
kotlinx_serialization = "1.7.1"
ksp = "2.0.10-1.0.24"
ktor = "2.3.12"
ktorfit = "2.0.1"
napier = "2.7.1"
jetbrainsKotlinJvm = "1.9.0"
room = "2.7.0-alpha06"
security_crypto = "1.1.0-alpha06"
skie = "0.8.4"
sqlite = "2.5.0-SNAPSHOT"
da...@google.com <da...@google.com> #12
From what have you shared things look 'fine', I know it might be a lot of work, but if you could try and create a small repro, so you don't have to share your whole project, but validate in a smaller project that things work as expected to try and determine if its something in your setup or with Room. If the concern is sharing your project in this public forum then if possible I will happily look at it if you share it privately sending me an email at danysantiago at google dot com.
[Deleted User] <[Deleted User]> #13
Again thanks a lot for all you help :)
da...@google.com <da...@google.com>
[Deleted User] <[Deleted User]> #14
i've sent you an invite .. thanks in advance :)
om...@gmail.com <om...@gmail.com> #15
Here is my reproducer @Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
for the generated code. Otherwise, I cannot set allWarningsAsErrors = true
.
da...@google.com <da...@google.com> #16
re
da...@google.com <da...@google.com> #17
re @Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
? Thats normal, you can also configure the warning suppression in the Gradle file as described in
om...@gmail.com <om...@gmail.com> #18
re
git clone https://github.com/Omico/picsum.git -b ios
- Run
./gradlew assemble
- e:file:///Users/omico/Git/Omico/picsum/picsum/core/data/database/src/commonMain/kotlin/me/omico/picsum/data/database/PicsumDatabaseConstructor.kt:9:8 Object 'PicsumDatabaseConstructor' is not abstract and does not implement abstract member 'initialize'.
da...@google.com <da...@google.com> #19
re
[Deleted User] <[Deleted User]> #20
Your fix works prefect!!! thank you very much for all your help!
and have a good day :)
om...@gmail.com <om...@gmail.com> #21
re
Just one question, it seems to me that we can get XXDatabase info through the @Database annotation. I haven't seen the specific code, but I guess XXDatabase_Impl is also generated in this way? Is it possible generate expect object XXDatabaseConstructor : RoomDatabaseConstructor<XXDatabase>
automatally without any intervention?
a....@gmail.com <a....@gmail.com> #22
Hi folks! I still experience the issue with the latest room version: room = "2.7.0-alpha07" room-bundled = "2.5.0-alpha07"
plugins {
id("gradle.module.common")
alias(libs.plugins.room)
alias(libs.plugins.ksp)
}
android {
namespace = "mobile.data.database.implementation"
}
kotlin {
sourceSets {
commonMain {
dependencies {
implementation(projects.database.api)
implementation(projects.common.logger)
implementation(projects.common.utils)
implementation(libs.room.runtime)
implementation(libs.room.sqlite.bundled)
}
}
}
}
room {
schemaDirectory("$projectDir/schemas")
}
dependencies {
// Android
add("kspAndroid", libs.room.compiler)
// iOS
add("kspIosSimulatorArm64", libs.room.compiler)
add("kspIosX64", libs.room.compiler)
add("kspIosArm64", libs.room.compiler)
}
gradle.module.common
a plugin that has a basic multimodule structure such as applying "com.android.library", "org.jetbrains.kotlin.multiplatform", providing build types, compile options, source sets, compilerOptions.jvmTarget, and ksp sources sets.
The last one is the following
configureKspSourceSets() {
extensions.configure<LibraryExtension> {
libraryVariants.all {
sourceSets {
getByName(name) {
kotlin.srcDir("build/generated/ksp/$name/kotlin")
}
getByName("test") {
java.srcDir("src/test/kotlin")
}
}
}
}
AppDatabaseConstructor.kt:7:8 Object 'AppDatabaseConstructor' is not abstract and does not implement abstract member 'initialize'
da...@google.com <da...@google.com> #23
re
Do add override fun initialize()
to your expect object AppDatabaseConstructor
if mentioned by the compiler error, this is sometimes needed when compiling metadata (say if you are using Koin).
a....@gmail.com <a....@gmail.com> #24
Thank you,
adding initialize() did resolve the issue
expect object AppDatabaseConstructor : RoomDatabaseConstructor<AppDatabase> {
override fun initialize(): AppDatabase
}
Description
Component used: Room KMP, Versions used: Kotlin: 2.0.0 KSP: 2.0.0-1.0.24 Room: 2.7.0-alpha06 Sqlite: 2.5.0-alpha06 Koin: 3.5.3 Koin annotations: 1.3.1 AGP: 8.5.2 Gradle: 8.7
I'm experimenting with Room for KMP (Android/iOS), but running into this issue when implementing.
Project setup: My shared module has several submodules, one of which is
storage
, which contains the Room implementation.As per the docs, I created the AppDatabase, the AppDatabaseConstructor and the first few entities/DAOs. IDE shows no errors, but when trying to run the Android app, it shows
e: file:///<directory>/MyProject/shared/storage/src/commonMain/kotlin/com/example/myproject/shared/storage/database/Database.kt:56:8 Object 'AppDatabaseConstructor' is not abstract and does not implement abstract member 'initialize'.
The
actual
implementations forAppDatabaseConstructor
are generated correctly. The error points to theexpect object
Relevant files:
build.gradle.kts (module :shared:storage)
Database.kt (commonMain)
PlatformDatabaseBuilder.kt (commonMain)
PlatformDatabaseBuilder.android.kt (androidMain)
PlatformDatabaseBuilder.ios.kt (iosMain)