realm / realm-java

Realm is a mobile database: a replacement for SQLite & ORMs
http://realm.io
Apache License 2.0
11.46k stars 1.75k forks source link

Realm in a kotlin multiplatform project #6774

Closed Sara-Tareq closed 4 years ago

Sara-Tareq commented 4 years ago

I have a kotlin multiplatform library project where I'm using realm in the androidMain part of it , now I'm facing an issue and can't seem to find a solution for it . I have a class called CacheEntry which extends RealmObject

open class CacheEntry(var url: String = "", var data: RealmObject? = null,var expiry: Int = -1) : RealmObject() {
}

I also added a RealmModule class since it's a library project

@RealmModule(library = true ,classes = [CacheEntry::class])
open class LibModule {
}

when building I'm getting the error :

/networking/build/generated/source/kapt/debug/io/realm/net_intigral_networking_data_local_CacheEntryRealmProxy.java:193: error: package io.realm.io_realm_RealmObjectRealmProxy does not exist
        builder.addPersistedLinkProperty("data", RealmFieldType.OBJECT, io.realm.io_realm_RealmObjectRealmProxy.ClassNameHelper.INTERNAL_CLASS_NAME);
cmelchior commented 4 years ago

Hi @Sara-Tareq Are you still having issues. It sounds like the annotation processor isn't running for some reason. If you can provide a sample project that demonstrate the issue, we can investigate.

promanowicz commented 4 years ago

Not sure, but this might be related with this issue. When I tried to use Realm in multiplatform project i receive this gradle message for plugin version 5.14.0

Kotlin Multiplatform Projects are an experimental feature. app: 'annotationProcessor' dependencies won't be recognized as kapt annotation processors. Please change the configuration name to 'kapt' for these artifacts: 'io.realm:realm-annotations-processor:5.14.0', 'io.realm:realm-annotations-processor:5.14.0'.

When I switch to 6.1.0 or 7.0.0 I receive

Configuration with name 'kapt' not found.

rorbech commented 4 years ago

Have you tried to

apply plugin: 'kotlin-kapt'

before the applying the realm-android plugin?

cmelchior commented 4 years ago

Closing due to inactivity. Feel free to reopen if this is still an issue or you can provide more info on how to reproduce.

ahmettekik commented 4 years ago

I came across this same issue yesterday. My class was as the following:

open class UnfinishedUserInterfaceFlow @JvmOverloads constructor(
        var data: RealmObject? = null,
        var flowTypeString: String = "",
        @PrimaryKey var id: Long = 0): RealmObject() {
    val flowType : FlowType
        get() {
            return try {
                FlowType.valueOf(flowTypeString)
            } catch (e: IllegalArgumentException) {
                FlowType.ActivateBasal
            }
        }
}

I guess you can't possibly use a RealmObject as your type and you need to have a subclass of a RealmObject according to here. Just writing this for newbies like me