Search code examples
androidrealmkotlin

Kotlin - Use Realm Module in android


I have an android app with Realm and some Realm Module that help me to isolate synced Realm and i decide to migrate from Java to 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()
}

function getShop return RealmConfiguration to use in Realm.getInstance(). After some converting show me some error when build() has occurred:

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

please help me to continue my migration. I can't understand what's wrong because this method works for me in java.
UPDATE:
After good Q&A in comments and so many change and try in my project i found when using kotlin in my project ShopModuleMediator was not generated and when convert app project from Java to Kotlin project has worked befor clean Project.


Solution

  • 🎉🎉 Congratulation with release Realm Java 4.1.0 this problem has been resolved and i share my test project you can see result but an important note that for using in instant app you must use https network and can't use http in instant app and i share another app that work when run in app mode but when run in instantapp has occurred an error : not permitted by network security policy this is because using http in authentication url.