2016-09-13 22 views
2

我创建了SelfGeneration Kotlin的领域类,并且在添加项目不再构建之后。我该如何解决?添加Realm类后无法创建Android项目

@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 { 
    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 
} 

摇篮错误:

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

+0

你可以显示更多的build.gradle,你的'buildScript'块中有那些依赖关系吗? –

+0

尝试重新启动您的IDE:https://youtrack.jetbrains.com/issue/KT-12912 – nhaarman

+1

问题出现在即时运行模式下,当我禁用它时,一切都变好了 – Griill

回答

2

Android Studio中即时运行功能和境界是不兼容的。使用此功能可能会导致许多非显而易见的错误和编译时间或运行时间。包括你正在报道的那个。

在Android中,当使用即时运行功能时,一些执行字节码操作的插件可能无法正常运行。在documentation for Instant Run它说:

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

境界talks about their change to use bytecode weaving在编译时间,所以这是有可能在编译时或运行时与即时运行打破插件的类型。当然,在Realm issue 1832他们谈论的问题即时运行(有超过28 issues with the phrase "Instant Run"在境界问题跟踪器)。其他堆栈溢出问题也会讨论这些问题,例如:Realm causes my app to crash when trying to build a RealmConfiguration

目前唯一的解决方案是在Android Studio偏好设置中禁用即时运行功能,清理项目,然后再次构建/运行。