& quot; kotlin-noarg& amp;"插件不要在Realm中工作 [英] "kotlin-noarg" plugin don't work in Realm

查看:52
本文介绍了& quot; kotlin-noarg& amp;"插件不要在Realm中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

"kotlin-allopen"插件有效,但"kotlin-noarg"插件无效.我该怎么办?

"kotlin-allopen" plugin work but "kotlin-noarg" plugin don't work. How can I do?

下面是代码.

build.gradle

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
}

app/build.gradle

app/build.gradle

apply plugin: 'realm-android'

NoArg.kt

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.SOURCE)
annotation class NoArg

MyApplication.kt

MyApplication.kt

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        Realm.init(this)
    }
}

AndroidManifest.xml

AndroidManifest.xml

<application
    android:name=".MyApplication"

SampleEntity.kt

SampleEntity.kt

@NoArg
@AllOpen
@RealmClass
data class SampleEntity(var sample: String?) : RealmModel

在构建时,显示以下错误.类"SampleEntity"必须声明一个不带参数的公共构造函数(如果它包含自定义构造函数).

when build, the following error was displayed.Class "SampleEntity" must declare a public constructor with no arguments if it contains custom constructors.

它可以与领域一起使用吗?

Does it work with realm?

推荐答案

这是预期的行为.从文档中: https://kotlinlang.org/docs/reference/compiler-plugins.html#no-arg-compiler-plugin

This is intended behaviour. From the documentation: https://kotlinlang.org/docs/reference/compiler-plugins.html#no-arg-compiler-plugin

生成的构造函数是合成的,因此不能直接调用从Java或Kotlin,但可以使用反射调用

The generated constructor is synthetic so it can’t be directly called from Java or Kotlin, but it can be called using reflection

这篇关于&amp; quot; kotlin-noarg&amp; amp;&quot;插件不要在Realm中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆