Realm documentation in Kotlin


Now that Kotlin is the official modern language for Android, could you add a Kotlin documentation similar to how there is for Swift? There are many things that have to be specified differently due to Kotlin/Swift’s non-nullability and readonly-ness – so for example using @LinkingObjects( … ) in Kotlin gives the error “@LinkingObjects field “” must be final”. It can take quite a bit of trial/error/research to find out how to get around this in Kotlin – would be incomparably better if the official Realm docs instead showcased the way.


You mean you would like our examples in the doc section to show both Kotlin and Java?


Good point, mbradea. It does take trial and error to get it working. For example, your RealmModel Kotlin classes must be declared open in order to work with Realm.

I have not had an issue getting up and running as it is pretty quick to learn the ropes with Kotlin and Realm but the docs can always get better, right?

If you need help on specific topics, please reach out. I myself have been only writing in Kotlin for past 1 1/2 years with Realm and love it. Happy to help.


well “must be made final” means that it should be declared as val

Otherwise, the other fields must all be var, and the class must be open, and if there are constructor parameters then they must all have default value.


Hi, I’m a newbie to Realm & Kotlin building an Android version of my iOS app.
I’ve started by building a simple project to understand the basics of Realm.
I have got completely stuck with the 2 following error messages and the course tutor I’m following has been unable to work out what the problem is.

  1. Cause: io.realm.com_xxxx_realmtest_DogRealmProxyInterface
  2. This Realm is not part of the schema.
    Which one of these errors seems to depend which order I put this lines in the
    apply plugin: ‘kotlin-android’
    apply plugin: ‘realm-android’
    My main activity and Dog.kt file are below.
    Hopefully you can point me in the right direction here. Thanks in advance if you are able to look at this.

import android.os.Bundle
import io.realm.Realm
import io.realm.RealmObject

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {

    val realm = Realm.getDefaultInstance()
    val myDog = realm.createObject( = "Fido"
    myDog.age = 10

    val query = realm.where(Dog ::
    val results = query.findAll()
    for (dog in results) {


import io.realm.RealmObject
import io.realm.RealmModel

open class Dog : RealmObject() {
var name = “”
var age = 0



You need the plugins in the order specified here:
You can also take a look at our Kotlin example here:


Thanks thats cleared things up a bit.
I now just get the error;
io.realm.exceptions.RealmException: Dog is not part of the schema for this Realm

I notice that in my MainActivity.kt the import of Dog is grey and unused even though I have the line
val myDog = realm.createObject()


I think the point made in the main post on this thread is good and still valid. I initially started using Realm with Swift, and I found that the documentation was pretty good and I was able to find some solid examples to work from. Using Realm with Kotlin has been a lot more frustrating.

Dedicated Kotlin docs would be helpful. I’d really like to see some more complex example projects though. The kotlin example git is very simple.