question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android - Realm does not work in a project with more than one module

See original GitHub issue

Goal

  • I have 2 modules where realm is located. One handles the database generic and another the database of the actually application. However When I try to add a RealmObject to the @RealmModule class it keeps telling me the RealmObject is not an object. However, if I change the location of the class to the application database module it actually works…

Exception trying to compile is the following:

e: error: RealmOne could not be added to the module. Only classes extending RealmObject or implementing RealmModel, which are part of this project, can be added.

Steps & Code to Reproduce

Application Module

  • UserRealmModule
@RealmModule(classes = [RealmOne::class, RealTwo::class], library = true)
class UserRealmModule

Generic Database Module

  • RealmOne
open class RealmOne(
    @Required
    @PrimaryKey
    @RealmField(REALM_ONE_ID)
    var id: String = ""
) : RealmObject() 
  • RealmTwo
open class RealmTwo(
    @Required
    @PrimaryKey
    @RealmField(REALM_TWO_ID)
    var id: String = ""
) : RealmObject() 

Version of Realm and tooling

Realm version(s): {{io.realm:realm-gradle-plugin:5.8.0 }}

Android Studio version: 3.5.2

Android Build Tools version: 28.0.3

Gradle version: com.android.tools.build:gradle:3.5.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
cmelchiorcommented, Nov 20, 2019

@luispereira Why not just expose a module from the generic database module and combine them when opening the Realm?

 RealmConfiguration.Builder()
            .name(storageName)
            .schemaVersion(REALM_CURRENT_VERSION)
            .migration(realmMigrate)
            .modules(GenericModule(), UserModule())
            .deleteRealmIfMigrationNeeded()
1reaction
luispereiracommented, Nov 20, 2019

Yes @Zhuinden, but wouldn’t that impact only runtime? I’m having an issue in compile time

 RealmConfiguration.Builder()
            .name(storageName)
            .schemaVersion(REALM_CURRENT_VERSION)
            .migration(realmMigrate)
            .modules(UserRealmModule())
            .deleteRealmIfMigrationNeeded()
Read more comments on GitHub >

github_iconTop Results From Across the Web

Realm Android - Multiple RealmModule for mutiple libraries
As it looks like, the problem was that the two modules were creating a single instance of the Realm object, which then lead...
Read more >
Realm: Create reactive mobile apps in a fraction ... - MongoDB
Missing Realm Constructor · Close all simulators/device builds · Stop the package manager running in terminal (or better yet, just restart terminal) ·...
Read more >
Create reactive mobile apps in a fraction of the time - Realm
We do not support Java outside of Android at the moment. ... Your Realm version needs to be higher than 0.81.1. ... RealmModule...
Read more >
Realm on Android Library (module)
How to configure your realm instance on multi-module projects. ... RealmObject is not part of the schema I have run into this error...
Read more >
Known issues with Android Studio and Android Gradle Plugin
To fix this issue, upgrade your Android 11 emulator to version 9 or higher by navigating to Tools > SDK Manager. In the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found