“kotlin-noarg”插件在Realm中不起作用
“kotlin-allopen”插件工作,但“kotlin-noarg”插件不工作。 我能怎么做?
下面是代码。
的build.gradle
buildscript { ext.kotlin_version = '1.1.3-2' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0-beta2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version" classpath "io.realm:realm-gradle-plugin:3.5.0" } } apply plugin: "kotlin-allopen" apply plugin: "kotlin-noarg" allOpen { annotation("sample.AllOpen") } noArg { annotation("sample.NoArg") invokeInitializers = true }
应用程序/的build.gradle
apply plugin: 'realm-android'
NoArg.kt
@Target(AnnotationTarget.CLASS) @Retention(AnnotationRetention.SOURCE) annotation class NoArg
MyApplication.kt
class MyApplication : Application() { override fun onCreate() { super.onCreate() Realm.init(this) } }
AndroidManifest.xml中
<application android:name=".MyApplication"
SampleEntity.kt
@NoArg @AllOpen @RealmClass data class SampleEntity(var sample: String?) : RealmModel
当构建时,显示以下错误。 Class "SampleEntity" must declare a public constructor with no arguments if it contains custom constructors.
它是否适用于领域?
这是打算的行为。 从文档: https : //kotlinlang.org/docs/reference/compiler-plugins.html#no-arg-compiler-plugin
生成的构造函数是合成的,所以不能直接从Java或Kotlin调用,但可以使用反射来调用它
- Realm&Kotlin:DefaultRealmModuleMediator.java – > error:unreachable statement
- Android Kotlin Realm正确的方法来查询+更新异步
- 境界,findAllSorted和独特
- 如何将RealmResults <Object>转换为List <Object>
- 无法在RealmObject子类中创建ArrayList
- “对象”不是这个域的模式的一部分
- 领域返回陈旧的数据
- Android,领域,Gradle:错误:注释处理器:找不到RealmProcessor
- 当我添加将RealmObject扩展到我的项目的ChatInformation kotlin类时,无法建立项目,错误在哪里?