Search code examples
javaandroidcloudrealm

Realm.io - use outside of Android (in Java)


I'm considering switching from Firebase DB to Realm.io for my Android app.

From what I've read - https://realm.io/docs/java/latest/#getting-started :

We do not support Java outside of Android at the moment.

That seems like an odd limitation for such a (supposedly) mature library.

I'm thinking that this could complicate e.g. automatic testing, requiring tests to be run on device/emulator, slowing things down a lot.

Questions:

Is it really the case that it cannot be used outside of Android?

What is the reason of this limitation?

Is it really as bad as I think?

What if I want to have some auxiliary server app (written in Java) running somewhere in the cloud, e.g. AppEngine, to connect to the realm DB. Is that option excluded?

What workarounds are there, e.g. for testing and server-side Java?

For the latter purpose - is NodeJS server-side app supported?


Solution

  • That seems like an odd limitation for such a (supposedly) mature library.

    It's not that odd a limitation if you consider the fact that Realm ships its own native core, and the JNI wrapper written for the Android NDK; and it hasn't been detached from it yet to make it platform-agnostic, and as such for example relies on Android-specific things in certain places - for example, notifications, using the "Looper" as its specific event loop implementation.

    Technically, the realm-java binding has plans to support Java outside of Android, but it currently does not. You should think of it more-so as realm-android than realm-java at this time.


    Realm-Core at the time did not support UWP and Windows yet, although now realm-dotnet project works for Windows as well. Even so, detaching Realm-Java's implementation from Android is difficult.

    I'm thinking that this could complicate e.g. automatic testing, requiring tests to be run on device/emulator, slowing things down a lot.

    For testing Realm-specific behavior, yes.

    For testing other things in your app with unit tests, no. You just need the right design, and some mocks I guess.

    Is it really the case that it cannot be used outside of Android?

    It works on iOS and Android as a local database.

    It also works on Linux as a local server-side database since this article from Nov 16 2016, using a similar (the same?) API to the React-Native Realm API, via NodeJS.


    You can also run a Realm Object Server (ROS) free of charge on whatever Linux or MacOS machine you like.

    Then you can use the sync API to connect to said ROS, and automatically synchronize Realm associated with a user to the ROS. That's what you can do with ROS for free.

    With the Enterprise Professional Edition and its price, you can also (on the server side) read/write to Sync Realms, and listen to events that alter the Sync Realm via the NodeJS Realm API.

    Is it really as bad as I think?

    That is up to your own interpretation.

    What if I want to have some auxiliary server app (written in Java) running somewhere in the cloud, e.g. AppEngine, to connect to the realm DB. Is that option excluded?

    Your Java application will currently not be able to communicate with a Realm on the server-side.

    NodeJS only.

    Even then, the "synchronized" Realms that auto-update all data between devices through to ROS to reflect whatever is in the ROS is a paid feature.

    Basically, Realm-Java currently only supports Android. As it said in the docs.


    As for communicating with a local Realm for the server side on a Linux via the NodeJS API, sure, go ahead.

    For the latter purpose - is NodeJS server-side app supported?

    NodeJS is able to write to Realms on Linux machines. Possibly also Mac OS.

    Free version is local Realm only. Paid version is synchronized Realm stuff through the ROS.