本文介绍了Realm Android javassist.NotFoundException:io.realm.com_example_realmtest_data_SomethingRealmProxyInterface的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android领域的新手,我从简单的kotlin-project开始,只有一个只有一个字段的实体.

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
}

我在Application类中初始化了Realm:

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.

推荐答案

因此,事实证明,我只需要在模块级别 build.gradle 中使用apply plugin: 'kotlin-kapt'.看起来Kotlin需要生成这些类.由于这个愚蠢的错误,我浪费了很多时间,所以我希望这个答案能对遇到类似错误的人们有所帮助.

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.

编辑

并且正如注释中提到的 musoof 一样,apply plugin: 'kotlin-kapt'的顺序很重要.您必须将其包括在apply plugin: 'realm-android'之前.否则,您仍然会收到相同的错误.

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.

这篇关于Realm Android javassist.NotFoundException:io.realm.com_example_realmtest_data_SomethingRealmProxyInterface的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 08:36