“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调用,但可以使用反射来调用它