Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Realm Android javassist.NotFoundException: io.realm.com_example_realmtest_data_SomethingRealmProxyInterface

I was completely new to realm in android, and I started from simple kotlin-project with only one entity which had only one field.

open class Something : RealmObject() {
   @PrimaryKey 
   var id: Long = 0
}

I initialized Realm in my Application class:

class RealmApp : Application() {

    override fun onCreate() {
        super.onCreate()

        Realm.init(this)
        val config = RealmConfiguration.Builder().build()
        Realm.setDefaultConfiguration(config)
    }
}

And, of course I added realm plugin:

//Project level
dependencies {
    ...
    classpath "io.realm:realm-gradle-plugin:5.9.0"
}

//Module level
apply plugin: 'realm-android'

Simple project, but every time I tried to compile it, exception appeared:

Caused by: javassist.NotFoundException: io.realm.com_example_realmtest_data_SomethingRealmProxyInterface
at javassist.ClassPool.get(ClassPool.java:452)
at io.realm.transformer.BytecodeModifier$Companion.addRealmProxyInterface(ByteCodeModifier.kt:96)
at io.realm.transformer.build.BuildTemplate.transformModelClasses(BuildTemplate.kt:109)
at io.realm.transformer.RealmTransformer.transform(RealmTransformer.kt:107)
at com.android.build.api.transform.Transform.transform(Transform.java:288)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:239)
at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:235)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)

I searched for whole day to solve this problem, but didn't find anything.

like image 571
Ruslan Avatar asked Feb 21 '19 14:02

Ruslan


1 Answers

So it turned out that I simply needed apply plugin: 'kotlin-kapt' in my module level build.gradle. Looks like Kotlin need that to generate these classes. I lost a lot of time because of that silly mistake, so I hope that this answer will help people that are getting similar error.

EDIT

And as musoof mentioned in the comments, order of apply plugin: 'kotlin-kapt' matters. You have to include it before apply plugin: 'realm-android'. Otherwise you will still get the same error.

like image 131
Ruslan Avatar answered Nov 03 '22 11:11

Ruslan