2

I've created SelfGeneration Realm class with Kotlin and after adding that the project is no longer building. How do I fix this?

@RealmClass open class SelfGeneration() : BaseRealmObject { @PrimaryKey override var id: Int? = null open var type: ItemType? = null open var model: String? = null open var watt: Int? = null companion object { fun getById(id: Int): SelfGeneration { val realm = Realm.getDefaultInstance() val selfGeneration = realm.where(SelfGeneration::class.java) .equalTo(BaseRealmObject.Field.ID, id) .findFirst() return realm.copyFromRealm(selfGeneration) } } } 

Dependencies:

dependencies { classpath com.android.tools.build:gradle:2.1.3 classpath io.realm:realm-gradle-plugin:1.2.0 classpath com.neenbedankt.gradle.plugins:android-apt:1.8 classpath "com.fernandocejas.frodo:frodo-plugin:0.8.1 } 

Gradle error:

Error:Execution failed for task javassist.
NotFoundException: com.theappsolution.conectric.model.SelfGeneration

4
  • can you show more of your build.gradle, are those dependencies in your buildScript block? Commented Sep 13, 2016 at 15:42
  • Try restarting your IDE: youtrack.jetbrains.com/issue/KT-12912 Commented Sep 13, 2016 at 16:05
  • 1
    the issue was in instant run mode, when i disabled it everything became ok Commented Sep 14, 2016 at 7:19
  • Griill, I made notes in my answer below about instant run problems and Realm, there are likely more than just this one, so is good to turn instant run off for now. Commented Sep 15, 2016 at 23:13

1 Answer 1

2

Android Studio Instant Run feature and Realm are not compatible. And using this feature can cause many non-obvious errors and compile time or runtime. Including the one you are reporting.

In Android, when using Instant Run feature some plugins that do byte code manipulation may not function correctly. In the documentation for Instant Run it says:

Certain third-party plugins that perform bytecode enhancement may cause issues with how Instant Run instruments your app. If you experience these issues, but want to continue using Instant Run, you should disable those plugins for your debug build variant. You can also help improve compatibility with third-party plugins by filing a bug

Realm talks about their change to use bytecode weaving at compile time so this is the type of plugin that might break with Instant Run either at compile time or at runtime. And sure enough in the Realm issue 1832 they talk about problems with Instant Run (there are over 28 issues with the phrase "Instant Run" in the Realm issue tracker). Also other Stack Overflow questions talks about these problems, such as: Realm causes my app to crash when trying to build a RealmConfiguration.

The only current solution is to disable the Instant Run feature in Android Studio preferences, clean your project, and then build/run again.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.