Status Update
Comments
da...@google.com <da...@google.com> #2
Branch: androidx-master-dev
commit b90079595f33f58fece04026a97faa0d243acdb1
Author: Yuichi Araki <yaraki@google.com>
Date: Wed Sep 18 16:55:49 2019
Change the way to detect mismatch between POJO and query
This fixes cursor mismatch warnings with expandProjection.
Bug: 140759491
Test: QueryMethodProcessorTest
Change-Id: I7659002e5e0d1ef60fc1af2a625c0c36da0664d8
M room/compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
M room/compiler/src/test/kotlin/androidx/room/processor/QueryMethodProcessorTest.kt
M room/compiler/src/test/kotlin/androidx/room/testing/TestProcessor.kt
ei...@gmail.com <ei...@gmail.com> #3
da...@gmail.com <da...@gmail.com> #4
Branch: androidx-master-dev
commit bdde5a1a970ddc9007b28de4aa29d60ffa588f08
Author: Yigit Boyar <yboyar@google.com>
Date: Thu Apr 16 16:47:05 2020
Re-factor how errors are dismissed when query is re-written
This CL changes how we handle errors/warnings if query is
re-written.
There was a bug in expandProjection where we would report warnings
for things that Room already fixes automatically (
The solution to that problem (I7659002e5e0d1ef60fc1af2a625c0c36da0664d8)
solved it by deferring validating of columns until after re-write
decision is made. Unfortunately, this required changing PojoRowAdapter
to have a dummy mapping until it is validating, make it hard to use
as it does have a non-null mapping which is not useful.
This CL partially reverts that change and instead rely on the log
deferring logic we have in Context. This way, we don't need to break
the stability of PojoRowAdapter while still having the ability to
drop warnings that room fixes. This will also play nicer when we
have different query re-writing options that can use more information
about the query results.
Bug: 153387066
Bug: 140759491
Test: existing tests pass
Change-Id: I2ec967c763d33d7a3ff02c1a13c6953b460d1e5f
M room/compiler/src/main/kotlin/androidx/room/log/RLog.kt
M room/compiler/src/main/kotlin/androidx/room/processor/QueryMethodProcessor.kt
M room/compiler/src/main/kotlin/androidx/room/solver/TypeAdapterStore.kt
M room/compiler/src/main/kotlin/androidx/room/solver/query/result/PojoRowAdapter.kt
ja...@gmail.com <ja...@gmail.com> #5
da...@google.com <da...@google.com> #6
Sorry, no mayor update. We are trying to figure out a better way for connecting runtime code with the generated database class such that referencing the generated instantiateImpl()
is avoided. But since there is no reflection in native-land our options are limited.
Note that the instantiateImpl
is generated in the same package as the @Database
annotated class, so you might need an import if used from a different package: import <database-package>.instantiateImpl
However, most of the time if instantiateImpl()
can't be resolved then it is a signal that Room's annotation processor is not being properly applied. Due to KMP and its multiple targets there is no easy-way (single line) way of applying the processor (without creating some helper of course). Also the way K2 / KSP2 behave with regards to KMP changed (see @Database
definition is in the common source set and then reference common generated code from the other non-common sets.
ra...@gmail.com <ra...@gmail.com> #7
Adding
sourceSets.commonMain {
kotlin.srcDir("build/generated/ksp/metadata")
}
Did the trick
ei...@gmail.com <ei...@gmail.com> #8
I still got InstantiateImpl Unresolved reference error. If you need a mvp for reproduction, let me know and I will create one for you
sa...@softwarejourneys.co <sa...@softwarejourneys.co> #9
```
sourceSets.commonMain {
kotlin.srcDir("build/generated/ksp/metadata")
}
````
works in ios but android failed cause
Class 'AppDatabase_Impl' is not abstract and does not implement abstract base class member 'clearAllTables'.
tried just import the single file of AppDatabase_InstantiateImpl but was not posible since required a directory
ya...@gmail.com <ya...@gmail.com> #10
You can build with Kotlin 2.0 by implementing the following code. You need to override the clearAllTables method.
ro...@gmail.com <ro...@gmail.com> #11
I was not able to replicate success in Kotlin 2.0 / KSP2 using the technique created by cvivek07. Also not successful with using the aforementioned code:
sourceSets.commonMain {
kotlin.srcDir("build/generated/ksp/metadata")
}
I can build successfully on Android or Native Kotlin, but not iOS.
da...@google.com <da...@google.com> #12
I made a comment on a KSP bug which I think is causing this issue:
In the meantime you can workaround this with the following changes:
- Apply the processor to the metadata compilation only:
dependencies {
add("kspCommonMainMetadata", libs.androidx.room.compiler)
}
- Add a task dependency to the KSP metadata task:
tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinCompile<*>>().configureEach {
if (name != "kspCommonMainKotlinMetadata" ) {
dependsOn("kspCommonMainKotlinMetadata")
}
}
- Add the metadata generated sources to the other targets:
kotlin {
sourceSets {
commonMain {
kotlin.srcDir("build/generated/ksp/metadata")
}
}
}
Note that the above workaround makes sense as long as you have your @Database
in the common source sets. With the workaround you might encounter the following bug: clearAllTables()
, like this:
// Due to https://issuetracker.google.com/348166275
interface ClearAllTablesWorkaround {
fun clearAllTables(): Unit {}
}
@Database(...)
abstract class TheDatabase : RoomDatabase() {
// ...
override fun clearAllTables() {
super.clearAllTables()
}
}
da...@google.com <da...@google.com> #13
Hey all, we are thinking of making some API changes to fix this issue, support Kotlin 2.0 and avoid the workaround in
First and foremost, we still expect the processor to be applied to all end targets (iosX64
, linux64
, iosArm64
, etc) and not the common compilation. Second, we'll remove the need to use the generated extension function instantiateImpl()
and instead it will be replaced by user defined code, which helps avoid the red lines in the IDE and the confusion of referencing a to-be-generated function.
The setup would look like this (new API names are all TBD):
- Define an
expect object
that will know how to build the database
// src/commonMain
expect object MyDatabaseCtor : RoomDatabaseConstructor<MyDatabase>
- Link the object with the
@Database
declaration by using a new annotation
// src/commonMain
@Database(...)
@ConstructedBy(MyDatabaseCtor::class) // NEW
abstract class MyDatabase : RoomDatabase
- Build a new database instance as usual but without passing a factory
// src/iosMain
fun createNewDatabase(path: String) =
Room.databaseBuilder<AppDatabase>(name = path)
.setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
.build()
A prototype of this has been implemented but not released, just sharing it here for early feedback. Thanks!
ro...@gmail.com <ro...@gmail.com> #14
ap...@google.com <ap...@google.com> #15
Branch: androidx-main
commit 19309786e1e720aebb977d0e73f21017156ae67d
Author: Daniel Santiago Rivera <danysantiago@google.com>
Date: Thu Jul 04 10:51:06 2024
Update Room initialization strategy for KMP
Changes Room reflection replacement strategy for KMP to one where Room generates an 'actual' implementations of an 'expect object' that is linked via an @AssociatedObjectKey annotated annotation in the @Database definition, that ultimately allows the builder; at runtime, to find the object, cast it to a known interface and invoke the generated override function that instantiates the generated database implementation.
Bug: 316978491
Bug: 338446862
Bug: 342905180
Test: ./gradlew :room:integration-tests:room-testapp-multiplatform:allTests
Relnote: """Changes the instantiation setup for a RoomDatabase in a KMP project.
Due to Kotlin 2.0 compilation model, the strategy of referencing a to-be-generated function, named 'instantiateImpl()' is longer viable. Two new APIs, @ConstructedBy and RoomDatabaseConstructor are introduced that replace the 'instantiateImpl()' strategy. The new strategy is as follow:
1. Define an expect object that implements RoomDatabaseConstructor
```
expect object MyDatabaseCtor : RoomDatabaseConstructor<MyDatabase>
```
2. Link the object with the @Database declaration using @ConstructedBy
```
@Database(...)
@ConstructedBy(MyDatabaseCtor::class) // NEW
abstract class MyDatabase : RoomDatabase
```
3. Create a new database instance but without passing a factory argument
```
fun createNewDatabase(path: String) =
Room.databaseBuilder<AppDatabase>(name = path)
.setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
.build()
```
"""
Change-Id: Ic787a5c84f318dea0e004cd35efb2202bc6902dc
M room/integration-tests/multiplatformtestapp/build.gradle
M room/integration-tests/multiplatformtestapp/src/androidInstrumentedTest/kotlin/androidx/room/integration/multiplatformtestapp/test/BuilderTest.kt
M room/integration-tests/multiplatformtestapp/src/commonTest/kotlin/androidx/room/integration/multiplatformtestapp/test/BaseAutoMigrationTest.kt
M room/integration-tests/multiplatformtestapp/src/commonTest/kotlin/androidx/room/integration/multiplatformtestapp/test/BaseMigrationTest.kt
M room/integration-tests/multiplatformtestapp/src/commonTest/kotlin/androidx/room/integration/multiplatformtestapp/test/BaseTypeConverterTest.kt
M room/integration-tests/multiplatformtestapp/src/commonTest/kotlin/androidx/room/integration/multiplatformtestapp/test/SampleDatabase.kt
M room/integration-tests/multiplatformtestapp/src/jvmTest/kotlin/androidx/room/integration/multiplatformtestapp/test/BuilderTest.kt
M room/integration-tests/multiplatformtestapp/src/nativeTest/kotlin/androidx/room/integration/multiplatformtestapp/test/AutoMigrationTest.kt
M room/integration-tests/multiplatformtestapp/src/nativeTest/kotlin/androidx/room/integration/multiplatformtestapp/test/BuilderTest.kt
M room/integration-tests/multiplatformtestapp/src/nativeTest/kotlin/androidx/room/integration/multiplatformtestapp/test/InvalidationTest.kt
M room/integration-tests/multiplatformtestapp/src/nativeTest/kotlin/androidx/room/integration/multiplatformtestapp/test/MigrationTest.kt
M room/integration-tests/multiplatformtestapp/src/nativeTest/kotlin/androidx/room/integration/multiplatformtestapp/test/QueryTest.kt
M room/integration-tests/multiplatformtestapp/src/nativeTest/kotlin/androidx/room/integration/multiplatformtestapp/test/TypeConverterTest.kt
M room/room-common/api/current.txt
M room/room-common/api/restricted_current.txt
M room/room-common/bcv/native/current.txt
M room/room-common/build.gradle
A room/room-common/src/commonMain/kotlin/androidx/room/ConstructedBy.kt
M room/room-common/src/commonMain/kotlin/androidx/room/Database.kt
A room/room-common/src/jvmMain/kotlin/androidx/room/ConstructedBy.jvm.kt
A room/room-common/src/nativeMain/kotlin/androidx/room/ConstructedBy.native.kt
M room/room-compiler/src/main/kotlin/androidx/room/DatabaseProcessingStep.kt
M room/room-compiler/src/main/kotlin/androidx/room/ext/xpoet_ext.kt
M room/room-compiler/src/main/kotlin/androidx/room/processor/Context.kt
M room/room-compiler/src/main/kotlin/androidx/room/processor/DatabaseProcessor.kt
M room/room-compiler/src/main/kotlin/androidx/room/processor/ProcessorErrors.kt
M room/room-compiler/src/main/kotlin/androidx/room/vo/Database.kt
A room/room-compiler/src/main/kotlin/androidx/room/writer/DatabaseObjectConstructorWriter.kt
D room/room-compiler/src/main/kotlin/androidx/room/writer/InstantiateImplWriter.kt
A room/room-compiler/src/test/kotlin/androidx/room/processor/DatabaseConstructorProcessorTest.kt
M room/room-compiler/src/test/kotlin/androidx/room/verifier/DatabaseVerifierTest.kt
M room/room-compiler/src/test/kotlin/androidx/room/vo/DatabaseTest.kt
M room/room-compiler/src/test/kotlin/androidx/room/writer/DatabaseObjectConstructorWriterKotlinCodeGenTest.kt
A room/room-compiler/src/test/test-data/kotlinCodeGen/actualDatabaseConstructor.kt
D room/room-compiler/src/test/test-data/kotlinCodeGen/instantiateImpl_simple.kt
M room/room-gradle-plugin/src/test/test-data/multiplatform-project/src/commonMain/kotlin/room/testapp/CommonDatabase.kt
M room/room-gradle-plugin/src/test/test-data/multiplatform-project/src/jvmMain/kotlin/room/testapp/MyDatabase.kt
M room/room-gradle-plugin/src/test/test-data/multiplatform-project/src/nativeMain/kotlin/room/testapp/MyDatabase.kt
M room/room-runtime/api/current.txt
M room/room-runtime/api/restricted_current.txt
M room/room-runtime/bcv/native/current.txt
M room/room-runtime/src/androidMain/kotlin/androidx/room/Room.android.kt
A room/room-runtime/src/commonMain/kotlin/androidx/room/RoomDatabaseConstructor.kt
M room/room-runtime/src/jvmMain/kotlin/androidx/room/Room.jvm.kt
M room/room-runtime/src/nativeMain/kotlin/androidx/room/Room.native.kt
M room/room-runtime/src/nativeMain/kotlin/androidx/room/util/KClassUtil.native.kt
M room/room-testing/bcv/native/current.txt
M room/room-testing/src/nativeMain/kotlin/androidx/room/testing/MigrationTestHelper.native.kt
da...@google.com <da...@google.com> #16
The next release of Room will contain the updated strategy for initializing Room in a KMP project, if you are eager to validate it you can do so with snapshot builds from
ma...@gmail.com <ma...@gmail.com> #17
It should be noted the the actual implementations of the RoomDatabaseConstructor expects will be generated by KSP. Warnings/errors can be ignored, at least until after you do a rebuild.
The 3rd step is specifically for the ios (or apple) side of things, no changes are needed for the android equivalent.
And I ran into build cache/ksp issues and had to do a full clean/rebuild.
an...@gmail.com <an...@gmail.com> #18
Hi! I'm still waiting for a quick solution to the problems generated in iOS
This is my data:
kotlin = "2.0.0" room = "2.7.0-alpha06" ksp = "2.0.0-1.0.21" sqlite = "2.5.0-SNAPSHOT"
import com.google.devtools.ksp.gradle.KspTaskMetadata import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.androidApplication) alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.compose.compiler) alias(libs.plugins.kotlin.serialization) alias(libs.plugins.ksp) alias(libs.plugins.room) }
kotlin { androidTarget { @OptIn(ExperimentalKotlinGradlePluginApi::class) compilerOptions { jvmTarget.set(JvmTarget.JVM_11) } } listOf( iosX64(), iosArm64(), iosSimulatorArm64() ).forEach { iosTarget -> iosTarget.binaries.framework { baseName = "ComposeApp" isStatic = true linkerOpts.add("-lsqlite3") } }
sourceSets {
androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
implementation(libs.core.splashscreen)
implementation(libs.ktor.client.okhttp)
implementation(libs.koin.android)
implementation(libs.koin.androidx.compose)
implementation(libs.xml.util.core.android)
implementation(libs.room.runtime.android)
}
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.bundles.ktor)
api(libs.datastore.preferences)
api(libs.datastore)
api(libs.koin.core)
implementation(libs.koin.compose)
implementation(libs.koin.compose.viewmodel)
implementation(libs.lifecycle.viewmodel)
implementation(libs.navigation.compose)
implementation(libs.xml.util.core)
implementation(libs.xml.util.serialization)
implementation(libs.room.runtime)
implementation(libs.sqlite.bundled)
}
nativeMain.dependencies {
implementation(libs.ktor.client.darwin)
}
sourceSets.commonMain {
kotlin.srcDir("build/generated/ksp/metadata")
}
}
}
android { namespace = "com.itlab.match_academico" compileSdk = libs.versions.android.compileSdk.get().toInt()
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
defaultConfig {
applicationId = "com.itlab.match_academico"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
buildFeatures {
compose = true
}
dependencies {
debugImplementation(compose.uiTooling)
}
}
room { schemaDirectory("$projectDir/schemas") }
dependencies { add("kspCommonMainMetadata", libs.room.compiler) add("kspAndroid", libs.room.compiler) afterEvaluate { add("kspIosSimulatorArm64", libs.room.compiler) add("kspIosX64", libs.room.compiler) add("kspIosArm64", libs.room.compiler) } }
kotlin.sourceSets.commonMain { tasks.withType<KspTaskMetadata> { kotlin.srcDir(destinationDirectory) } }
My db:
package features.configIni.data.database
import androidx.room.ConstructedBy import androidx.room.Database import androidx.room.RoomDatabase import androidx.room.RoomDatabaseConstructor
@Database( entities = [ WebServiceRoom::class ], version = 1 ) @ConstructedBy(WebServiceDatabaseConstructor::class) abstract class WebServiceDatabase: RoomDatabase() { abstract fun webserviceDao(): WebServiceDao }
expect object WebServiceDatabaseConstructor : RoomDatabaseConstructor<WebServiceDatabase>
const val DATABASE_NAME = "webService.db"
On Android, everything works fine but on iOS I get the error:
Expected WebServiceDatabaseConstructor has no actual declaration in module
when according to the official doc it does not require me to set the actual declaration
ya...@gmail.com <ya...@gmail.com> #19
I was able to build both Android/iOS with room = "2.7.0-alpha06".
I had to change composeApp/build.gradle.kts.
Solution
// libs.versions.toml
[versions]
kotlin = "2.0.10"
roomVersion = "2.7.0-alpha06"
sqlite = "2.5.0-alpha06"
ksp = "2.0.0-1.0.21"
[libraries]
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "roomVersion" }
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "roomVersion" }
sqlite-bundled = { module = "androidx.sqlite:sqlite-bundled", version.ref = "sqlite" }
[plugins]
room = { id = "androidx.room", version.ref = "roomVersion" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
// composeApp/build.gradle.kts
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import java.util.Properties
plugins {
...
// room
alias(libs.plugins.ksp)
alias(libs.plugins.room)
}
kotlin {
...
sourceSets {
...
iosMain {
// To provide RoomDatabaseConstructor actual declaration
kotlin.srcDir("build/generated/ksp/metadata")
dependencies {
...
}
}
}
}
dependencies {
...
// Room
add("kspCommonMainMetadata", libs.androidx.room.compiler)
add("kspAndroid", libs.androidx.room.compiler)
}
room {
schemaDirectory("$projectDir/schemas")
}
Create the following classes according to the official documentation.
- shared/src/commonMain/kotlin/Database.kt
- shared/src/androidMain/kotlin/Database.kt
- shared/src/iosMain/kotlin/Database.kt
Build
- Android Studio > Build > Clean Project
- Android Studio > Build > Rebuild Project
vi...@gmail.com <vi...@gmail.com> #20
#libs.version.toml
...
ksp = "2.0.0-1.0.21" # "1.9.23-1.0.19"
androidx-room = "2.7.0-alpha06" #2.7.0-alpha04" #"2.7.0-alpha01"
...
#shared/build.gradle.kts
plugins {
...
alias(libs.plugins.ksp)
alias(libs.plugins.room)
...
}
kotlin {
...
sourceSets {
...
iosMain {
kotlin.srcDir("build/generated/ksp/metadata")
dependencies {
...
}
}
}
}
dependencies {
// "kspAndroid"(libs.androidx.room.compiler) // For AndroidUnitTest
// "kspCommonMainMetadata"(libs.androidx.room.compiler)
add("kspCommonMainMetadata", libs.androidx.room.compiler)
add("kspAndroid", libs.androidx.room.compiler)
add("kspIosSimulatorArm64", libs.androidx.room.compiler)
add("kspIosX64", libs.androidx.room.compiler)
add("kspIosArm64", libs.androidx.room.compiler)
}
#ZDCKeyCoreDatabase.kt
@Database(entities = [UserEntity::class], version = KMPConstants.DATABASE_VERSION, exportSchema = true)
@ConstructedBy(ZDCKeyCoreDatabaseConstructor::class)
abstract class ZDCKeyCoreDatabase : RoomDatabase() {
abstract fun getUserDao(): UserDao
}
@Suppress("EXPECT_ACTUAL_CLASSIFIERS_ARE_IN_BETA_WARNING")
expect object ZDCKeyCoreDatabaseConstructor: RoomDatabaseConstructor<ZDCKeyCoreDatabase>
But the build is getting failed with below error.
e:file:///Users/..../kmp_project/zdckey_core/build/generated/ksp/metadata/commonMain/kotlin/com/..../zdckey_core/data/database/ZDCKeyCoreDatabaseConstructor.kt:5:22 'actual object ZDCKeyCoreDatabaseConstructor : RoomDatabaseConstructor<ZDCKeyCoreDatabase>' has no corresponding expected declaration
e:file:///Users/..../kmp_project/zdckey_core/build/generated/ksp/metadata/commonMain/kotlin/com/..../zdckey_core/data/database/ZDCKeyCoreDatabaseConstructor.kt:5:22 ZDCKeyCoreDatabaseConstructor: expect and corresponding actual are declared in the same module.
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
Suggestions to solve this issue would be highly appreciated. Thanks in advance.
da...@google.com <da...@google.com> #21
Since this have changed a between alpha05 and alpha06 (and alpha07), please double check your build Gradle file configuration.
- Please apply it to all your 'end' targets (this list is exhaustive but only use the ones relevant to your project):
dependencies {
// Android
add("kspAndroid", libs.androidx.room.compiler)
// JVM (Desktop)
add("kspJvm", libs.androidx.room.compiler)
// Linux
add("kspLinuxX64", libs.androidx.room.compiler)
add("kspLinuxArm64", libs.androidx.room.compiler)
// Mac
add("kspMacosX64", libs.androidx.room.compiler)
add("kspMacosArm64", libs.androidx.room.compiler)
// iOS
add("kspIosSimulatorArm64", libs.androidx.room.compiler)
add("kspIosX64", libs.androidx.room.compiler)
add("kspIosArm64", libs.androidx.room.compiler)
}
Note that applying the processor to the kspCommonMainMetadata
should not be needed.
- Do not manually add KSP generated sources from other targets:
// DO NOT DO THIS
iosMain {
kotlin.srcDir("build/generated/ksp/metadata")
}
This just leads to errors due to the differences of generated code between the platforms, which is why its important that on step 1 the Room KSP processor is applied to all targets that will use the common sources set where the @Database
is defined.
- Do not declare explicit task dependencies:
// DO NOT DO THIS
kotlin.sourceSets.commonMain {
tasks.withType<KspTaskMetadata> {
kotlin.srcDir(destinationDirectory)
}
}
Declaring direct dependencies and adding generated sources by KSP is a red flag, these where workarounds from alpha05 that shouldn't be needed with the newer @ConstructedBy
strategy in alpha06.
- Do not create the
actual
of theexpect object
class that implementedRoomDatabaseConstructor
// shared/src/commonMain/kotlin/Database.kt
expect object MyDatabaseCtor: RoomDatabaseConstructor<MyDatabaseCtor> {
fun initialize(): MyDatabaseCtor
}
// shared/src/nativeMain/kotlin/Database.kt
// DO NOT DO THIS
actual object MyDatabaseCtor: RoomDatabaseConstructor<MyDatabaseCtor> {
fun initialize(): MyDatabaseCtor { ... }
}
-
Make sure Kotlin version matches KSP version, i.e. if using Kotlin 2.0.10 then use KSP 2.0.10-1.0.24
-
If using Kotlin 2.x then the
kotlin.native.disableCompilerDaemon = true
is not needed and can lead to another issue (https://youtrack.jetbrains.com/issue/KT-69523 ). -
If you are using the Compose Gradle Plugin and Room Gradle Plugin along with Kotlin 2.0 then you might see a separate issue regarding the plugins along the lines of
Cannot change attributes of configuration ':<project>:debugFrameworkIosX64' after it has been locked for mutation
, the workaround is to remove the Room Gradle Plugin and configure the schema directory via KSP arguments, seehttps://issuetracker.google.com/343408758 -
If you had the workaround for
clearAllTables()
, please remove it, it is no needed since Room is being applied to 'end' targets.
Feel free to comment even if the steps mentioned here don't work for you.
vi...@gmail.com <vi...@gmail.com> #22
Thanks a lot for the quick response and clarifying all the confusions.
All the mentioned checklist are verified. But the build fails with the following error.
e:file:///Users/..../kmp_project/zdckey_core/src/commonMain/kotlin/com/..../zdckey_core/data/database/ZDCKeyCoreDatabase.kt:22:8 Object 'ZDCKeyCoreDatabaseConstructor' is not abstract and does not implement abstract member 'initialize'.
#ZDCKeyCoreDatabase.kt
@Database(entities = [UserEntity::class], version = KMPConstants.DATABASE_VERSION, exportSchema = true)
@ConstructedBy(ZDCKeyCoreDatabaseConstructor::class)
abstract class ZDCKeyCoreDatabase : RoomDatabase() {
abstract fun getUserDao(): UserDao
}
expect object ZDCKeyCoreDatabaseConstructor: RoomDatabaseConstructor<ZDCKeyCoreDatabase>
Kindly share us the solution. Thanks in advance..
an...@gmail.com <an...@gmail.com> #23
I just followed the suggestions of
null cannot be cast to non-null type org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
These are my classes
@Database( entities = [ WebServiceRoom::class ], version = 1 ) @ConstructedBy(WebServiceDatabaseConstructor::class) abstract class WebServiceDatabase: RoomDatabase() { abstract fun webserviceDao(): WebServiceDao }
expect object WebServiceDatabaseConstructor : RoomDatabaseConstructor<WebServiceDatabase>
const val DATABASE_NAME = "webService.db"
Ios: fun getWebServicesDatabase(): RoomDatabase.Builder<WebServiceDatabase>{ val dbFilePath = documentDirectory() + "/$DATABASE_NAME" return Room.databaseBuilder<WebServiceDatabase>( name = dbFilePath, ) }
@OptIn(ExperimentalForeignApi::class) private fun documentDirectory(): String { val documentDirectory = NSFileManager.defaultManager.URLForDirectory( directory = NSDocumentDirectory, inDomain = NSUserDomainMask, appropriateForURL = null, create = false, error = null, ) return requireNotNull(documentDirectory?.path) }
import database.getWebServicesDatabase import features.configIni.data.datasource.ConfigIniService import io.ktor.client.engine.darwin.Darwin import networking.createHttpClient import org.koin.dsl.module
actual val platformModule = module { single { createHttpClient(Darwin.create()) } single { ConfigIniService(get()) } single { getWebServicesDatabase() } }
Gradle: import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.androidApplication) alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.compose.compiler) alias(libs.plugins.kotlin.serialization) alias(libs.plugins.ksp) alias(libs.plugins.room) }
kotlin { androidTarget { @OptIn(ExperimentalKotlinGradlePluginApi::class) compilerOptions { jvmTarget.set(JvmTarget.JVM_11) } } listOf( iosX64(), iosArm64(), iosSimulatorArm64() ).forEach { iosTarget -> iosTarget.binaries.framework { baseName = "ComposeApp" isStatic = true linkerOpts.add("-lsqlite3") } }
sourceSets {
androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
implementation(libs.core.splashscreen)
implementation(libs.ktor.client.okhttp)
implementation(libs.koin.android)
implementation(libs.koin.androidx.compose)
implementation(libs.xml.util.core.android)
implementation(libs.room.runtime.android)
}
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.bundles.ktor)
api(libs.datastore.preferences)
api(libs.datastore)
api(libs.koin.core)
implementation(libs.koin.compose)
implementation(libs.koin.compose.viewmodel)
implementation(libs.lifecycle.viewmodel)
implementation(libs.navigation.compose)
implementation(libs.xml.util.core)
implementation(libs.xml.util.serialization)
implementation(libs.room.runtime)
implementation(libs.sqlite.bundled)
}
iosMain {
dependencies{
implementation(libs.ktor.client.darwin)
}
}
}
}
android { namespace = "com.itlab.match_academico" compileSdk = libs.versions.android.compileSdk.get().toInt()
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
defaultConfig {
applicationId = "com.itlab.match_academico"
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 1
versionName = "1.0"
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
buildFeatures {
compose = true
}
dependencies {
debugImplementation(compose.uiTooling)
}
}
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) }
kotlin = "2.0.10" room = "2.7.0-alpha06" ksp = "2.0.0-1.0.21" sqlite = "2.5.0-SNAPSHOT"
kotlin.code.style=official
#Gradle org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options="-Xmx2048M"
#Android android.nonTransitiveRClass=true android.useAndroidX=true
#Kotlin Multiplatform kotlin.mpp.enableCInteropCommonization=true
#Room kotlin.native.disableCompilerDaemon = true ksp.useKSP2=true
da...@google.com <da...@google.com> #24
If you are using Kotlin 2.0.10
please make sure you use matching KSP version 2.0.10-1.0.24
If you encounter an error with Cannot change attributes of configuration ':<project>:debugFrameworkIosX64' ...
then please see the workaround in
da...@google.com <da...@google.com> #25
Another important thing is that kotlin.native.disableCompilerDaemon = true
is not needed when using Kotlin 2.0.10, having it enable will lead to a different issue:
an...@gmail.com <an...@gmail.com> #26
Thank you very much for the prompt response, I really appreciate it!
I corrected your observations and I still have the same error in iOS Xcode,these are the logs I receive when I do the clean rebuild. I attached two images for a better look. Thanks for the support.
ma...@gmail.com <ma...@gmail.com> #27
Thanks! These steps helped me fix Android and iOS. JVM is giving issues: Configuration with name 'kspJvm' not found.
vi...@gmail.com <vi...@gmail.com> #28
Let me clarify something.. The room for client applications works properly when integrated with kmp library in local. i.e when using it as a whole/same project. But We would like to host library as a separate sdk.
I don't know how it is working for client applications. When we build the shared module(kmp) as standalone it shows error. But when we create new Android module within the project and access it from there it runs properly.
CASE: 1 //works fine
Project [
module1 = Android
module2 = kmp library
]
Shows compile error in module2 database file but while running the android application, all the room operations works fine.
CASE: 2 // our use case
Project [
module1 = kmp library
]
Build fails with the error saying 'The constructor is not abstract and does not implement abstract member initialize'.
We need to generate executables and host it as an sdk.
Kindly consider this use-case and provide us the solution.
Detailed error description:
e:file:///Users/..../kmp_project/zdckey_core/src/commonMain/kotlin/com/..../zdckey_core/data/database/ZDCKeyCoreDatabase.kt:21:8 Object 'ZDCKeyCoreDatabaseConstructor' is not abstract and does not implement abstract member 'initialize'.
an...@gmail.com <an...@gmail.com> #29
an...@gmail.com <an...@gmail.com> #30
Hello again
I corrected your observations and I still have the same error in iOS Xcode,these are the logs I receive when I do the clean rebuild. My error is: null cannot be cast to non-null type org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
I attached two images for a better look. Thanks for the support.
da...@google.com <da...@google.com> #31
re ./gradlew :composeApp:kspKotlinIosX64 --stacktrace
? The error null cannot be cast to non-null type org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
is new and might not be relevant to this specific bug.
vi...@gmail.com <vi...@gmail.com> #32
Our usecase is to generate aar and xcframework files from a standalone kmp library without any other android or ios modules.
Project [
module1 = kmp library
]
Detailed error description:
e:file:///Users/..../kmp_project/zdckey_core/src/commonMain/kotlin/com/..../zdckey_core/data/database/ZDCKeyCoreDatabase.kt:21:8 Object 'ZDCKeyCoreDatabaseConstructor' is not abstract and does not implement abstract member 'initialize'.
Is there any solutions for this usecase..! Kindly suggest any workaround. Thanks in advance..
an...@gmail.com <an...@gmail.com> #33
an...@gmail.com <an...@gmail.com> #34
re
This is the full stacktrace:
% ./gradlew :composeApp:kspKotlinIosX64 --stacktrace Type-safe project accessors is an incubating feature.
Task :composeApp:kspKotlinIosX64 FAILED e: [ksp] java.lang.NullPointerException: null cannot be cast to non-null type org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':composeApp:kspKotlinIosX64'. A failure occurred while executing com.google.devtools.ksp.gradle.KspAAWorkerAction null cannot be cast to non-null type org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl
Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights. Get more help at
Exception is: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':composeApp:kspKotlinIosX64'. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:130) at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:128) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:116) at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46) at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74) at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52) at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200) at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53) at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52) at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:331) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:318) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.lambda$execute$0(DefaultTaskExecutionGraph.java:314) at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:80) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:314) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303) at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463) at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64) at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47) Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.google.devtools.ksp.gradle.KspAAWorkerAction at org.gradle.workers.internal.DefaultWorkerExecutor$WorkItemExecution.waitForCompletion(DefaultWorkerExecutor.java:287) at org.gradle.internal.work.DefaultAsyncWorkTracker.lambda$waitForItemsAndGatherFailures$2(DefaultAsyncWorkTracker.java:130) at org.gradle.internal.Factories$1.create(Factories.java:31) at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLocks(DefaultWorkerLeaseService.java:336) at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLocks(DefaultWorkerLeaseService.java:319) at org.gradle.internal.work.DefaultWorkerLeaseService.withoutLock(DefaultWorkerLeaseService.java:324) at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:126) at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForItemsAndGatherFailures(DefaultAsyncWorkTracker.java:92) at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForAll(DefaultAsyncWorkTracker.java:78) at org.gradle.internal.work.DefaultAsyncWorkTracker.waitForCompletion(DefaultAsyncWorkTracker.java:66) at org.gradle.api.internal.tasks.execution.TaskExecution$3.run(TaskExecution.java:252) at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29) at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47) at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68) at org.gradle.api.internal.tasks.execution.TaskExecution.executeAction(TaskExecution.java:229) at org.gradle.api.internal.tasks.execution.TaskExecution.executeActions(TaskExecution.java:212) at org.gradle.api.internal.tasks.execution.TaskExecution.executeWithPreviousOutputFiles(TaskExecution.java:195) at org.gradle.api.internal.tasks.execution.TaskExecution.execute(TaskExecution.java:162) at org.gradle.internal.execution.steps.ExecuteStep.executeInternal(ExecuteStep.java:105) at org.gradle.internal.execution.steps.ExecuteStep.access$000(ExecuteStep.java:44) at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:59) at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:56) at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200) at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53) at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73) at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:56) at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:44) at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:41) at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:74) at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:55) at org.gradle.internal.execution.steps.PreCreateOutputParentsStep.execute(PreCreateOutputParentsStep.java:50) at org.gradle.internal.execution.steps.PreCreateOutputParentsStep.execute(PreCreateOutputParentsStep.java:28) at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:67) at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:37) at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:61) at org.gradle.internal.execution.steps.BroadcastChangingOutputsStep.execute(BroadcastChangingOutputsStep.java:26) at org.gradle.internal.execution.steps.CaptureOutputsAfterExecutionStep.execute(CaptureOutputsAfterExecutionStep.java:67) at org.gradle.internal.execution.steps.CaptureOutputsAfterExecutionStep.execute(CaptureOutputsAfterExecutionStep.java:45) at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:40) at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:29) at org.gradle.internal.execution.steps.BuildCacheStep.executeWithoutCache(BuildCacheStep.java:189) at org.gradle.internal.execution.steps.BuildCacheStep.lambda$execute$1(BuildCacheStep.java:75) at org.gradle.internal.Either$Right.fold(Either.java:175) at org.gradle.internal.execution.caching.CachingState.fold(CachingState.java:62) at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:73) at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:48) at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:46) at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:35) at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:76) at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$2(SkipUpToDateStep.java:54) at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:54) at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:36) at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:37) at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:27) at org.gradle.internal.execution.steps.ResolveIncrementalCachingStateStep.executeDelegate(ResolveIncrementalCachingStateStep.java:49) at org.gradle.internal.execution.steps.ResolveIncrementalCachingStateStep.executeDelegate(ResolveIncrementalCachingStateStep.java:27) at org.gradle.internal.execution.steps.AbstractResolveCachingStateStep.execute(AbstractResolveCachingStateStep.java:71) at org.gradle.internal.execution.steps.AbstractResolveCachingStateStep.execute(AbstractResolveCachingStateStep.java:39) at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:65) at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:36) at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:106) at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:55) at org.gradle.internal.execution.steps.AbstractCaptureStateBeforeExecutionStep.execute(AbstractCaptureStateBeforeExecutionStep.java:64) at org.gradle.internal.execution.steps.AbstractCaptureStateBeforeExecutionStep.execute(AbstractCaptureStateBeforeExecutionStep.java:43) at org.gradle.internal.execution.steps.AbstractSkipEmptyWorkStep.executeWithNonEmptySources(AbstractSkipEmptyWorkStep.java:125) at org.gradle.internal.execution.steps.AbstractSkipEmptyWorkStep.execute(AbstractSkipEmptyWorkStep.java:61) at org.gradle.internal.execution.steps.AbstractSkipEmptyWorkStep.execute(AbstractSkipEmptyWorkStep.java:36) at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:38) at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:36) at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:23) at org.gradle.internal.execution.steps.HandleStaleOutputsStep.execute(HandleStaleOutputsStep.java:75) at org.gradle.internal.execution.steps.HandleStaleOutputsStep.execute(HandleStaleOutputsStep.java:41) at org.gradle.internal.execution.steps.AssignMutableWorkspaceStep.lambda$execute$0(AssignMutableWorkspaceStep.java:35) at org.gradle.api.internal.tasks.execution.TaskExecution$4.withWorkspace(TaskExecution.java:289) at org.gradle.internal.execution.steps.AssignMutableWorkspaceStep.execute(AssignMutableWorkspaceStep.java:31) at org.gradle.internal.execution.steps.AssignMutableWorkspaceStep.execute(AssignMutableWorkspaceStep.java:22) at org.gradle.internal.execution.steps.ChoosePipelineStep.execute(ChoosePipelineStep.java:40) at org.gradle.internal.execution.steps.ChoosePipelineStep.execute(ChoosePipelineStep.java:23) at org.gradle.internal.execution.steps.ExecuteWorkBuildOperationFiringStep.lambda$execute$2(ExecuteWorkBuildOperationFiringStep.java:67) at org.gradle.internal.execution.steps.ExecuteWorkBuildOperationFiringStep.execute(ExecuteWorkBuildOperationFiringStep.java:67) at org.gradle.internal.execution.steps.ExecuteWorkBuildOperationFiringStep.execute(ExecuteWorkBuildOperationFiringStep.java:39) at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:46) at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:34) at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:48) at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:35) at org.gradle.internal.execution.impl.DefaultExecutionEngine$1.execute(DefaultExecutionEngine.java:61) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:127) at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:116) at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46) at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51) at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57) at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:74) at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52) at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200) at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53) at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73) at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52) at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:42) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:331) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:318) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.lambda$execute$0(DefaultTaskExecutionGraph.java:314) at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:80) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:314) at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:303) at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:463) at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:380) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64) at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47) Caused by: java.lang.NullPointerException: null cannot be cast to non-null type org.jetbrains.kotlin.load.java.structure.impl.JavaClassImpl at com.google.devtools.ksp.impl.symbol.kotlin.UtilKt.getDefaultValue(util.kt:590) at com.google.devtools.ksp.impl.symbol.kotlin.resolved.KSAnnotationResolvedImpl$defaultArguments$2.invoke(KSAnnotationResolvedImpl.kt:88) at com.google.devtools.ksp.impl.symbol.kotlin.resolved.KSAnnotationResolvedImpl$defaultArguments$2.invoke(KSAnnotationResolvedImpl.kt:64) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) at com.google.devtools.ksp.impl.symbol.kotlin.resolved.KSAnnotationResolvedImpl.getDefaultArguments(KSAnnotationResolvedImpl.kt:64) at com.google.devtools.ksp.impl.symbol.kotlin.resolved.KSAnnotationResolvedImpl$arguments$2.invoke(KSAnnotationResolvedImpl.kt:57) at com.google.devtools.ksp.impl.symbol.kotlin.resolved.KSAnnotationResolvedImpl$arguments$2.invoke(KSAnnotationResolvedImpl.kt:54) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) at com.google.devtools.ksp.impl.symbol.kotlin.resolved.KSAnnotationResolvedImpl.getArguments(KSAnnotationResolvedImpl.kt:54) at com.google.devtools.ksp.impl.symbol.kotlin.KSPropertyDeclarationImpl$annotations$2$4.invoke(KSPropertyDeclarationImpl.kt:76) at com.google.devtools.ksp.impl.symbol.kotlin.KSPropertyDeclarationImpl$annotations$2$4.invoke(KSPropertyDeclarationImpl.kt:72) at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:171) at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:194) at kotlin.sequences.FlatteningSequence$iterator$1.ensureItemIterator(Sequences.kt:331) at kotlin.sequences.FlatteningSequence$iterator$1.hasNext(Sequences.kt:318) at kotlin.sequences.SequencesKt___SequencesKt.any(_Sequences.kt:1240) at ksp.com.google.devtools.ksp.common.visitor.CollectAnnotatedSymbolsVisitor.visitAnnotated(CollectAnnotatedSymbolsVisitor.kt:37) at ksp.com.google.devtools.ksp.common.visitor.CollectAnnotatedSymbolsVisitor.visitPropertyDeclaration(CollectAnnotatedSymbolsVisitor.kt:82) at ksp.com.google.devtools.ksp.common.visitor.CollectAnnotatedSymbolsVisitor.visitPropertyDeclaration(CollectAnnotatedSymbolsVisitor.kt:33) at com.google.devtools.ksp.impl.symbol.kotlin.KSPropertyDeclarationImpl.accept(KSPropertyDeclarationImpl.kt:189) at ksp.com.google.devtools.ksp.common.visitor.CollectAnnotatedSymbolsVisitor.visitClassDeclaration(CollectAnnotatedSymbolsVisitor.kt:54) at ksp.com.google.devtools.ksp.common.visitor.CollectAnnotatedSymbolsVisitor.visitClassDeclaration(CollectAnnotatedSymbolsVisitor.kt:33) at com.google.devtools.ksp.impl.symbol.kotlin.KSClassDeclarationImpl.accept(KSClassDeclarationImpl.kt:175) at ksp.com.google.devtools.ksp.common.visitor.CollectAnnotatedSymbolsVisitor.visitFile(CollectAnnotatedSymbolsVisitor.kt:43) at ksp.com.google.devtools.ksp.common.visitor.CollectAnnotatedSymbolsVisitor.visitFile(CollectAnnotatedSymbolsVisitor.kt:33) at com.google.devtools.ksp.impl.symbol.kotlin.KSFileImpl.accept(KSFileImpl.kt:84) at com.google.devtools.ksp.impl.ResolverAAImpl.collectAnnotatedSymbols(ResolverAAImpl.kt:629) at com.google.devtools.ksp.impl.ResolverAAImpl.access$collectAnnotatedSymbols(ResolverAAImpl.kt:84) at com.google.devtools.ksp.impl.ResolverAAImpl$newAnnotatedSymbols$2.invoke(ResolverAAImpl.kt:640) at com.google.devtools.ksp.impl.ResolverAAImpl$newAnnotatedSymbols$2.invoke(ResolverAAImpl.kt:639) at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:74) at com.google.devtools.ksp.impl.ResolverAAImpl.getNewAnnotatedSymbols(ResolverAAImpl.kt:639) at com.google.devtools.ksp.impl.ResolverAAImpl.getSymbolsWithAnnotation(ResolverAAImpl.kt:621) at com.google.devtools.ksp.processing.Resolver.getSymbolsWithAnnotation$default(Resolver.kt:48) at androidx.room.compiler.processing.ksp.KspRoundEnv.getElementsAnnotatedWith(KspRoundEnv.kt:53) at androidx.room.compiler.processing.CommonProcessorDelegate.processRound(XBasicAnnotationProcessor.kt:95) at androidx.room.compiler.processing.ksp.KspBasicAnnotationProcessor.process(KspBasicAnnotationProcessor.kt:62) at com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:538) at com.google.devtools.ksp.impl.KSPLoader$Companion.loadAndRunKSP(KSPLoader.kt:36) at com.google.devtools.ksp.impl.KSPLoader.loadAndRunKSP(KSPLoader.kt) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at com.google.devtools.ksp.gradle.KspAAWorkerAction.execute(KspAATask.kt:510) at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63) at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:66) at org.gradle.workers.internal.NoIsolationWorkerFactory$1$1.create(NoIsolationWorkerFactory.java:62) at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100) at org.gradle.workers.internal.NoIsolationWorkerFactory$1.lambda$execute$0(NoIsolationWorkerFactory.java:62) at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44) at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41) at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:200) at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:195) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66) at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157) at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59) at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53) at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73) at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41) at org.gradle.workers.internal.NoIsolationWorkerFactory$1.execute(NoIsolationWorkerFactory.java:59) at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$0(DefaultWorkerExecutor.java:174) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:187) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.access$700(DefaultConditionalExecutionQueue.java:120) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner$1.run(DefaultConditionalExecutionQueue.java:162) at org.gradle.internal.Factories$1.create(Factories.java:31) at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:264) at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:128) at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:133) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:157) at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:126) ... 2 more Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to
BUILD FAILED in 2s 5 actionable tasks: 1 executed, 4 up-to-date
This is my build gradle
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.JvmTarget
plugins { alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.androidApplication) alias(libs.plugins.jetbrainsCompose) alias(libs.plugins.compose.compiler) alias(libs.plugins.kotlin.serialization) alias(libs.plugins.ksp) alias(libs.plugins.room) }
kotlin { androidTarget { @OptIn(ExperimentalKotlinGradlePluginApi::class) compilerOptions { jvmTarget.set(JvmTarget.JVM_11) } } listOf( iosX64(), iosArm64(), iosSimulatorArm64() ).forEach { iosTarget -> iosTarget.binaries.framework { baseName = "ComposeApp" isStatic = true linkerOpts.add("-lsqlite3") } }
sourceSets {
androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
implementation(libs.core.splashscreen)
implementation(libs.ktor.client.okhttp)
implementation(libs.koin.android)
implementation(libs.koin.androidx.compose)
implementation(libs.xml.util.core.android)
implementation(libs.room.runtime.android)
}
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.ui)
implementation(compose.components.resources)
implementation(compose.components.uiToolingPreview)
implementation(libs.bundles.ktor)
api(libs.datastore.preferences)
api(libs.datastore)
api(libs.koin.core)
implementation(libs.koin.compose)
implementation(libs.koin.compose.viewmodel)
implementation(libs.lifecycle.viewmodel)
implementation(libs.navigation.compose)
implementation(libs.xml.util.core)
implementation(libs.xml.util.serialization)
implementation(libs.room.runtime)
implementation(libs.sqlite.bundled)
}
iosMain {
dependencies{
implementation(libs.ktor.client.darwin)
}
}
} }
android { namespace = "com.itlab.match_academico" compileSdk = libs.versions.android.compileSdk.get().toInt()
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") sourceSets["main"].res.srcDirs("src/androidMain/res") sourceSets["main"].resources.srcDirs("src/commonMain/resources")
defaultConfig { applicationId = "com.itlab.match_academico" minSdk = libs.versions.android.minSdk.get().toInt() targetSdk = libs.versions.android.targetSdk.get().toInt() versionCode = 1 versionName = "1.0" } packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" } } buildTypes { getByName("release") { isMinifyEnabled = false } } compileOptions { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 } buildFeatures { compose = true } dependencies { debugImplementation(compose.uiTooling) } }
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) }
da...@google.com <da...@google.com> #35
re
re
vi...@gmail.com <vi...@gmail.com> #36
Below is the only error which we are facing.
Detailed error description:
e:file:///Users/..../kmp_project/zdckey_core/src/commonMain/kotlin/com/..../zdckey_core/data/database/ZDCKeyCoreDatabase.kt:21:8 Object 'ZDCKeyCoreDatabaseConstructor' is not abstract and does not implement abstract member 'initialize'.
The above error seems specific to the latest API change in alpha06. Actual implementations are generated by KSP in all the target sourcesets properly. But this error indicates that it expects implementation in commonmain too..
Kindly consider this error description and help us to find the root cause.. and the solution to fix it.
er...@gmail.com <er...@gmail.com> #37
e:file:///Users/..../kmp_project/zdckey_core/src/commonMain/kotlin/com/..../zdckey_core/data/database/ZDCKeyCoreDatabase.kt:21:8 Object 'ZDCKeyCoreDatabaseConstructor' is not abstract and does not implement abstract member 'initialize'.
Buddy. maybe you have some erros in ZDCKeyCoreDatabase.kt
.
You should not directly implement SDCKeyCoreDatabaseConstructor
. You let it be just expect object.
Can you upload the declaration of SDCKeyCoreDatabase
and implementation (in your case, it looks like you implement actual object) of ZDCKeyCoreDatabaseConstructor
?
vi...@gmail.com <vi...@gmail.com> #38
Nope.. brother, I didn't. I let the KSP to implement actuals in the respective target platforms and it did. i.e in androidMain and in iOSMain (in the build ->generated -> ksp folders obviously)
The problem here is as per the error description it seeks the implementation in commonMain where the expect object is defined. This is weird.
I hope the problem is clear now!
I will share the attachment for proof.
proof-1 will show the error description and the way i implemented ZDCCoreDatabase.
proof-2 will show that the actuals were generated by ksp in their respective target directories of build folder.
So please somebody look into the actual problem.. :).
er...@gmail.com <er...@gmail.com> #39
can I ask what proof_1.png
source is located in? It should be in commonMain
.
If you can find the auto-generated actual object, can you upload?
pr...@google.com <pr...@google.com> #40
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.room:room-common:2.7.0-alpha06
androidx.room:room-common-iosarm64:2.7.0-alpha06
androidx.room:room-common-iossimulatorarm64:2.7.0-alpha06
androidx.room:room-common-iosx64:2.7.0-alpha06
androidx.room:room-common-jvm:2.7.0-alpha06
androidx.room:room-common-linuxx64:2.7.0-alpha06
androidx.room:room-common-macosarm64:2.7.0-alpha06
androidx.room:room-common-macosx64:2.7.0-alpha06
androidx.room:room-compiler:2.7.0-alpha06
androidx.room:room-gradle-plugin:2.7.0-alpha06
androidx.room:room-runtime:2.7.0-alpha06
androidx.room:room-runtime-android:2.7.0-alpha06
androidx.room:room-runtime-iosarm64:2.7.0-alpha06
androidx.room:room-runtime-iossimulatorarm64:2.7.0-alpha06
androidx.room:room-runtime-iosx64:2.7.0-alpha06
androidx.room:room-runtime-jvm:2.7.0-alpha06
androidx.room:room-runtime-linuxx64:2.7.0-alpha06
androidx.room:room-runtime-macosarm64:2.7.0-alpha06
androidx.room:room-runtime-macosx64:2.7.0-alpha06
androidx.room:room-testing:2.7.0-alpha06
androidx.room:room-testing-android:2.7.0-alpha06
androidx.room:room-testing-iosarm64:2.7.0-alpha06
androidx.room:room-testing-iossimulatorarm64:2.7.0-alpha06
androidx.room:room-testing-iosx64:2.7.0-alpha06
androidx.room:room-testing-jvm:2.7.0-alpha06
androidx.room:room-testing-linuxx64:2.7.0-alpha06
androidx.room:room-testing-macosarm64:2.7.0-alpha06
androidx.room:room-testing-macosx64:2.7.0-alpha06
vi...@gmail.com <vi...@gmail.com> #41
Yes, of course it is located in commonMain.I haven't shared the package structure because it violates our org policy.
I will share the requested screenshots with blurred package names. Please check and let me know your thoughts..
vi...@gmail.com <vi...@gmail.com> #42
Hii pr...@google.com
I am not getting it.. We are already using 2.7.0-alpha06 only! which is where RoomDatabaseConstructor & @ConstructedBy annotation api's are introduced.
"It is possible this bug has only been partially addressed:"
Here you mean this usecase is missed in this version of release?. Kindly clarify us..
Is there any workaround?
da...@google.com <da...@google.com> #43
Here is a sample project using Kotlin 2.0, Compose KMP and Room KMP 2.7.0-alpha06 in a library module:
I hope it serves as guidance, otherwise without a small repro project it is hard for us to point you in the right direction to fix your issue. Let me know if it is helpful.
er...@gmail.com <er...@gmail.com> #44
In my opinion.. your compiler version doesn't support actual
/ expect
. Can you check your Kotlin, KSP, Compose Version and talk to me?
vi...@gmail.com <vi...@gmail.com> #45
Buddy, our compiler version does support expect & actual. We have expect actual implementations for network, datastore related apis in our project. The room constructedby API is the only problem we are facing.
If you ask for versions, we are using kotlin 2.0 and its compatible ksp version.
ha...@gmail.com <ha...@gmail.com> #46
Am facing the same error. Please took this as a priority. We are halfway into the release.
If it is an issue in this please let us know, we will look for alternatives for the time being. Kindly clarify us.
vi...@gmail.com <vi...@gmail.com> #47
Dear da...@google.com
Thanks a lot for taking time and build this sample project for us.
The mentioned issue reproduced in your project too. If we run the android application, it will run. But when we rebuild the project it will get failed throwing an error in the shared/library module.
e: file:///Users/.../Documents/RoomKmpLibraryExample/data/src/commonMain/kotlin/com/example/data/MyDatabase.kt:19:8 Object 'MyDatabaseCtor' is not abstract and does not implement abstract member 'initialize'.
In our use case we will not bind app and library modules in a same project. We will generate aar, xcframework files and host it in our org repository.
Attaching the screenshot for your reference.
Again, thanks for making the efforts. We sincerely appreciate it.
ph...@bayf.net <ph...@bayf.net> #48
After following all the guidance and checking the sample project I'm still getting: Object 'MyDatabaseCtor' is not abstract and does not implement abstract member 'initialize'
ma...@gmail.com <ma...@gmail.com> #49
er...@gmail.com <er...@gmail.com> #50
I have a similar error like yours when rebuild gradle.
'actual object AlarmDatabaseCtor : RoomDatabaseConstructor<AlarmDatabase>' has no corresponding expected declaration
However it works without error at my database.
da...@google.com <da...@google.com> #51
So it seems the issue is when either running ./gradlew build
or via Build -> Rebuild Project
in the IDE. This is important information since those actions tend to build 'too many things'. Specially it tries to build common source set in isolation (compileCommonMainKotlinMetadata
) which is a grey area in Kotlin right now, due to the expect / actual compilation model it is not possible to publish a 'common-only' library that has expect / actual as consumers can't contribute to those, i.e. you always publish -common
along side a platform.
I agree building via those two actions is broken. But are they hindering the rest of your project if iOS (via XCode), JVM Desktop (via ./gradlew composeApp:run
) and Android (via Android Studio) launch and work as expected? Or are they preventing you from publishing a library?
If it is still valuable to you to have a successful build via ./gradlew build
then we actually just made a fix for this (see initialize
override function in the expect object
and then the generated code will also include the actual
modifier. You can try this right now with a snapshot version of Room (see ./gradlew build
containing the fix in
ph...@bayf.net <ph...@bayf.net> #52
In my case, run via Android Studio, run via Xcode, Android CI (./gradlew build
) and iOS CI (xcodebuild archive
) are all broken with the same error. I've not managed to get a successful build to run with the latest alpha. It's a multi-module CMP project, it's virtually identical to your example project, in terms of Gradle and database initialisation, but with several entity types and DAOs added.
Edit: With snapshot, everything is working 👌🏻
vi...@gmail.com <vi...@gmail.com> #53
Thanks for the update da..@google.com. This is the clarity we want.. Some issue is found and it will be resolved in the next alpha release. This is the exact issue am trying to point out from beginning. As you mentioned this issue preventing us from publishing a library. I am glad this conversation has come to a conclusion. I sincerely appreciate your relentless response.
av...@gmail.com <av...@gmail.com> #54
From
on 8/15/2024: issue 358393367
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?
av...@gmail.com <av...@gmail.com> #55
From
on 8/11/2024: issue 358913889
Update! Problems solved by doing things
- disable room gradle plugin and rewrite
ksp { .... }
as you mentioned. - update kotlin and ksp version to 2.0.10
I think this is just temporary solution, however anyway it works now. I hope next version of room should be fixed ... :) thanks for your help!
st...@gmail.com <st...@gmail.com> #56
an...@gmail.com <an...@gmail.com> #57
Hi, I encountered a similar problem running KMM iOS build (room+ksp) and was able to resolve it by updating the dependencies.
room = "2.7.0-alpha08"
ksp = "2.0.20-1.0.25"
compose-plugin = "1.6.11"
kotlin = "2.0.20"
Description
Version used:
androidxRoom = "2.7.0-alpha02"
sqlite = "2.5.0-alpha02"
ksp = "1.9.23-1.0.19"
kotlin = "1.9.23"
and 1 try
kotlin = "2.0.0"
ksp = "2.0.0-1.0.21"
Devices/Android versions reproduced on:
iOS
fun getDatabaseBuilder(): RoomDatabase.Builder<AppDatabase> {
val dbFilePath = NSHomeDirectory() + "/location-database.db"
return Room.databaseBuilder<AppDatabase>(
name = dbFilePath,
factory = { AppDatabase::class.instantiateImpl() }
).setDriver(BundledSQLiteDriver())
.setQueryCoroutineContext(Dispatchers.IO)
}
Unresolved reference: instantiateImpl
ksp has generated an extension function whose name is instantiateImpl, but the project is not going to be built.
Unresolved reference: instantiateImpl
suggests adding a dependency - Add dependency on module 'project.module.core.iosX64Main'