4

I have one open class like this

open class NewsResponse(

@field:SerializedName("news")
val news: List<NewsItem?>? = null
):RealmObject()

And NewsItem class like this

open class NewsItem(

@field:SerializedName("created")
val created: String? = null,

@field:SerializedName("link")
val link: String? = null,

@field:SerializedName("description")
val description: String? = null,

@field:SerializedName("title")
val title: String? = null
):RealmObject()

I have also added

apply plugin: 'com.android.application'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android-extensions'

these plugins in app gradle

I have classpath "io.realm:realm-gradle-plugin:5.1.0" in project level gradle. So when I run the app, I get an error saying

Caused by: io.realm.exceptions.RealmException: NewsItem is not part of the schema for this Realm
    at io.realm.internal.modules.CompositeMediator.getMediator(CompositeMediator.java:180)

How to solve this problem?

2 Answers 2

8

Use this order:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
5
  • I have the same issue using the latest kotlin version and android studio. Even though the above solution was implemented the app still crash miserably
    – AouledIssa
    Oct 3, 2018 at 9:55
  • 1
    I've heard it also happens if you still have annotationProcessor scope somewhere instead of kapt Oct 3, 2018 at 10:16
  • I only have implementation and androidTestImplementation. There is no annotationProcessor. Maybe the Realm plugin is self uses this statement. If so we have no control over it as its gradle applied dependency.
    – AouledIssa
    Oct 3, 2018 at 10:31
  • 2
    If kotlin-kapt is applied before realm-android, then Realm will apply kapt scope since 2.2.0 or so Oct 3, 2018 at 10:46
  • 1
    I figured it out. apply plugin: 'kotlin-kapt was missing and yes apply plugin: 'realm-android' is the last applied. Thank you so much!
    – AouledIssa
    Oct 3, 2018 at 11:13
1

for me, i have to change my order to:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'kotlin-android'

and also add an empty constructor in my model class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.