Using Realm on MOE

I have a problem with adding Realm framework
when i add it as pod by Generating Java Bindings in 1.3 beta - How to do so?
and when i want to add binding there is nothing on this !

which way is better for this topic ? (use as framework or pod)
and i want to use this library on my java platform

please help!
Regards!

The question is how you want to use Realm:

  • the official Realm Java bindings. In this case you need to link with the Realm core and also link the Realm JNI bindings (I assume they created one for Android / Java), and include their Java API in your project as a dependency. This would be my recommendation, because this way you can share your Realm related Java code across Android and iOS.
  • Generate Java bindings from the Realm Objective-C / Swift bindings with Nat/J Gen. I don’t recommend this, because although you can access Realm from Java using this method, it will not be identical with the binding on Android.

Best Regards,
Gergely

Dear Gergely.

As you said about adding Realm database to common module : we can’t do this job because realm need android library and in ios gradle we have not access to add
apply plugin: ‘com.android.application’
apply plugin: ‘realm-android’

i ask this issue from realm team and they offered me to install ios framework
i have download (framework and pod) of realm for ios platform but the problem is where is header file !
there is so file after adding this module i have add Fabric to my project by this link Crash Reporting

this library is so use full

Saeed.
Regards !

Dear Saeed,

I assume that you try to use the community (open-source) version of Realm. I am confident that it should be possible to port the official Realm Java binding to MOE. They have an issue to support Java SE, but apparently it is low priority for them. MOE is closer to Android than to Java SE, however, we do not support Android specific APIs (except for android.util.Log) currently. They mention an AndroidNotifier class in the referenced GH issue, that should be most likely ported to MOE (e.g. using the iOS GCD API instead of Looper on Android).

I would love to see Realm Java supported on MOE. If you need help with the porting for your commercial project, feel free to contact us on our website, and we would be happy to provide you with a quote for porting Realm Java to MOE.

Best Regards,
Gergely

1 Like

I would like to use Realm as well, but the Android dependency killed it as an option, and I need a solution soon. Then looked into the Onyx database, and that one is promising, pure Java and open source as well. However, Onyx requires Java 8, and MOE right now only supports Java7.

The Java7 limitation is a problem for me in working with MOE, since many current libraries require Java8 now…

Which features of Java 8 are required by Onyx? Does it run on Android 6 or older? If yes, then it will work with MOE 1.x as well. MOE 1.x uses retrolambda to support lambda functions out of the box.

MOE 2.x will be based on Android 7, so there the level of Java 8 support will be the same as with Android 7.

While I have not yet used Realm, I did like the technology they developed, e.g. they have a native core which AFAIK stores the data in a platform / language independent manner, and they have language bindings for this core. They use mmap to provide high performance access to the data … etc.

I tried using Onyx on OEM, and got building complaints that java/util/Stream is not available.

From the onyx website:

Onyx Database V1.2.1 includes new features.
Android support added. We are proud to announce that Android is officially supported. You are now able to integrate the Onyx Embedded Database by using Jack & Jill compiler options. Onyx requires Java source compatibility 1.8. It will support Android OS starting with API version 9.

In this case MOE 2.x will support Onyx. You can expect the first alpha soon after the MOE 1.3 release.

Dear Gergely,

I’m really thankful about you’re fast replies and best supporting of MOE.
Whoever iam force to implement this API to our project.
If i getting closer to my goal i will put here a good step by step guide here to used for anyone.

Best Regards,
Saeed

Thanks Gergely, I will await the alpha then.

Dear @kisg , @blueneogeo and all friends,

I have worked on Realm database and finally i found a good way to connect Realm database to our MOE application’s.
at first it’s necessary to thankful from my friend Gergely about best supporting of MOE.

be sure you’re using MOE 1.3 and later

please follow all steps one by one and be careful to don’t forget any things.

  1. Create a MOE module then sync your gradle.

  2. Open terminal and cd to xcode directory.

  3. Close Xcode and be sure to it completely closed.

  4. Install pod from Install CocoaPods 0.39.0 or later. and then run pod init to create Podfile for you.

  5. In your Podfile, add pod ‘Realm’ to your app target and pod ‘Realm/Headers’ to your test target.

  6. From the command line, run pod install.

  7. Use the .xcworkspace file generated by CocoaPods to work on your project!

  8. You can see more detail from this link about realm database CocoaPod.

  9. In android studio open ios module gradle file and uncomment OR add following code under moe -> xcode :heart_eyes:

workspace ‘xcode/Sample.xcworkspace’
mainScheme ‘Sample’
testScheme ‘Sample-Test’

  1. Sync your gradle again.

  2. Right click on ios module under Multi-OS-Engine click on create new binding

  3. Click on :heavy_plus_sign: icon set Name: Realm and Choose Framework type then click OK

  4. Fill all textfield’s like this:
    Framework path: realm-objc-2.4.3/ios/dynamic/Realm.framework
    Base package name: com.example.sample.pods.realm
    Import Header:
    #import “Realm/Realm.h”

  5. In android studio click on :gear: then Generate Bindings (after a freezing android studio you will see Generate successfully)

  6. Now you need to create you’r object and save them on database.

  7. Open Xcode and create a cocoa touch (in this tutorial i will name’d it Person)
    Modify Person.h to

    #import <Foundation/Foundation.h>
    #import "RLMObject.h"
    @interface Person : RLMObject
    @property NSString *name;
    @property BOOL adopted;
    @end
  1. In AndroidStudio right click on ios module under Multi-OS-Engine click on create new binding

  2. Click on :heavy_plus_sign: icon set Name: Person and Choose Header type then click OK

  3. Fill all textfield’s like this:
    Header path: xcode/Sample
    Base package name: com.example.sample.model
    Explicit library: model
    Import Header:
    #import “Person.h”

  4. click on :gear: then Generate Bindings (after a freezing android studio you will see Generate successfully)

  5. Modify RLMObject.h, RLMResults.h and undo change’s, save again and close it.

  6. Open RLMRealm.java in android studio and modify defaultRealm method to:

    public static native RLMRealm defaultRealm();
  1. Open Person.java in android studio and add two following method’s:
    @Selector("allObjects")
    public static native RLMResults<Person> allObjects();
    @Generated
    @Selector("init")
    public native Person init();
  1. Finally done.

here a method for save and read result:

    public void save() {
        RLMRealm realm = RLMRealm.defaultRealm();
        Person person = Person.alloc().init();
        person.setName(name.text());
        person.setAdopted(false);
        realm.beginWriteTransaction();
        realm.addObject(person);
        realm.commitWriteTransaction();
    }

    public void showAll() {
        RLMResults<Person> results = Person.allObjects();

        for (int i = 0; i < results.count(); i++) {
            Person person = (Person) results.objectAtIndex(i);
            Foundation.NSLog("person : " + person.name(), "");
        }
    }

Best Regards,
Saeed.

4 Likes

Dear @saeed.motevalian.
Thank you for your description :slight_smile:

I’ve tried to connect Realm to my MOE apps according to yours steps but it doesn’t work.
Firstly, I had problem to bind Realm to Java.

When I fulfilled nbc file according to your descrption, I got error:

fatal error: ‘Realm/Realm.h’ file not found

Finally I bound my code using this fields:

Header path: “xcode/Pods/Realm”

Header search paths: “xcode/Pods/Headres
xcode/Pods/Headres/Private
xcode/Pods/Headres/Public”

Import headers: "#import “Realm/Realm.h”

Unfortunately, I cannot create object to save it to db.
When I try to create Person, Xcode shows error

“RLMObject.h” file not found

What am I doing wrong?

Dear @Wewe,

I had a tiny mistake on typing and fix it right now.

Check again when you add nbc file choose framework then select your framework path

Regards,
Saeed

Dear @saeed.motevalian

It still doesn’t work. I got error:
/Realm.framework/Headers/Realm.h:21:9: error: 'RLMArray.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/RLMArray.h:21:9: error: 'RLMCollection.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:22:9: error: 'RLMMigration.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/RLMMigration.h:74:70: warning: unknown attribute 'noescape' ignored [-Wunknown-attributes] /Realm.framework/Headers/Realm.h:23:9: error: 'RLMObject.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/RLMObject.h:21:9: error: 'RLMObjectBase.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/RLMObject.h:22:9: error: 'RLMThreadSafeReference.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:24:9: error: 'RLMObjectSchema.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:25:9: error: 'RLMPlatform.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:26:9: error: 'RLMProperty.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/RLMProperty.h:20:9: error: 'RLMConstants.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:27:9: error: 'RLMRealm.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/RLMRealm.h:296:46: warning: unknown attribute 'noescape' ignored [-Wunknown-attributes] /Realm.framework/Headers/RLMRealm.h:318:46: warning: unknown attribute 'noescape' ignored [-Wunknown-attributes] /Realm.framework/Headers/Realm.h:28:9: error: 'RLMRealmConfiguration.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:29:9: error: 'RLMRealmConfiguration+Sync.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:30:9: error: 'RLMResults.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:31:9: error: 'RLMSchema.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:32:9: error: 'RLMSyncConfiguration.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:33:9: error: 'RLMSyncCredentials.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:34:9: error: 'RLMSyncManager.h' file not found with <angled> include; use "quotes" instead /Realm.framework/Headers/Realm.h:35:9: error: 'RLMSyncPermission.h' file not found with <angled> include; use "quotes" instead fatal error: too many errors emitted, stopping now [-ferror-limit=]

Best Regards

Dear @Wewe,

It seems that you have a problem on nbc file
Please check the frameworks path
I hope you can find your problem.
Please create new projects and follow all steps agin.(don’t forget u need to use pod for xcode and framework for nbc file)

Regards,
Saeed

Is this the recommended approach to use Realm in MOE?

Just to be clear, if Realm had a pure Java implementation I could have the entire data layer in the commons module and reuse it for both platforms?

Dear @jirungaray,

Realm based on android.
Iam searching alot and finally know that :I need to put this api in both modules.

Regards,
Saeed.

@saeed any chance you can share your binding files?

follow this link