Search code examples
androidkotlinrealm

Realm. How to add new entity to database?


I'm new in Realm and I'm trying to create new entity in Realm database. First of all, I have a FolderItem class

data class FolderItem(
    val id: Int,
    var name: String,
    var postIds: List<FavoriteId>,
    var isChosen: Boolean
)

and according to Realm docs I decided to transform it to

open class FolderItem(
    @PrimaryKey val id: Int = 0,
    var name: String = "",
    var postIds: RealmList<FavoriteId> = RealmList(),
    var isChosen: Boolean = false
): RealmObject()

where FavoriteId is

open class FavoriteId(
    val postId: Int = 0,
    val wpId: Int? = null
): RealmObject()

But each time when I'm trying to build the project, I get the following error:

Execution failed for task ':logic:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
   > java.lang.reflect.InvocationTargetException (no error message)

I also found out that the error occurs as soon as I write: : RealmObject() and no matter what I write next.

Can you please help me figure out what the problem is?

P.S. Other Realm logic in project works fine


Solution

  • Add this to your gradle.properties file:

    kapt.use.worker.api=false
    kapt.incremental.apt=false