【问题标题】:Kotlin - Use Realm Module in androidKotlin - 在 android 中使用领域模块
【发布时间】:2017-09-01 07:54:08
【问题描述】:

我有一个带有 Realm 和一些 Realm Module 的 android 应用程序,可以帮助我隔离同步的 Realm,我决定从 Java 迁移到 Kotlin。

@RealmModule(classes = arrayOf(Category::class, Product::class))
private class ShopModule
fun getShop(user: SyncUser, path: String): RealmConfiguration {
    return SyncConfiguration.Builder(user, path)
            .modules(ShopModule())
            .build()
}

函数 getShop 返回 RealmConfiguration 以在 Realm.getInstance() 中使用。 经过一些转换后,当 build() 发生时显示一些错误:

io.realm.exceptions.RealmException: Could not find io.realm.ShopModuleMediator

请帮助我继续迁移。我不明白出了什么问题,因为这种方法在 java 中适用于我。
更新:
在 cmets 中进行了良好的问答并在我的项目中进行了如此多的更改和尝试后,我发现在我的项目中使用 kotlin 时,没有生成 ShopModuleMediator,并且当将应用程序项目从 Java 转换为 Kotlin 项目时,在 clean Project 中工作。

【问题讨论】:

  • 应用Gradle插件的顺序是什么? CategoryProduct 是用什么语言编写的?你的 Gradle 依赖项是什么,有没有标记为annotationProcessor
  • 嗨 @EpicPandaForce、CategoryProduct 是用 Kotlin 编写的。我使用com.android.tools.build:gradle:3.0.0-beta3,不使用任何annotationProcessor
  • 我不是在开玩笑,我需要您订购的插件apply plugin: 'blah'。特别是如果您以正确的顺序应用kotlin-kaptrealm-android
  • 抱歉@EpicPandaForce 我在当前功能中使用com.android.featurekotlin-androidkotlin-kaptkotlin-android-extensions,在基本功能中使用realm-android
  • 功能?此应用是免安装应用吗?

标签: android realm kotlin


【解决方案1】:

?? 恭喜发布 Realm Java 4.1.0 这个问题已经解决了,我分享 my test project 你可以看到结果,但重要的是要在即时应用程序中使用你 must use https network and can't use http in instant app 和我分享 another app 工作在应用程序模式下运行但在 Instantapp 中运行时发生错误:网络安全策略不允许这是因为在身份验证 url 中使用 http。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-21
    • 2017-10-18
    • 1970-01-01
    相关资源
    最近更新 更多