Adding Couchbase Lite to a MOE project

I’m very new to MOE and have gone through the getting started guide. I would like to learn a NoSQL database since I’ve never used one before and have decided on Couchbase Lite since it is a local database that is good for offline use.

I read the articles in the MOE docs under “Creating a Database App” that shows how to add SQLLite to your app, but I am a little confused with how to proceed with Couchbase Lite.

There is a Couchbase Lite version for Android located here:

And then the IOS version is here:

The SQLLite instructions in the MOE docs says to add it to the shared project that is used by both the IOS and Android versions of my app. But I’m not sure if that will work in this case.

If someone could point me in the right direction on how to get started with this it would be a big help.

Seems Couchbase has native library so in this case I believe you can’t directly add Couchbase to a shared module. You may need to add iOS version to iOS module and create java bindings using natJ, add android version to your android app module, then add an abstract layer so you could put your database logic into a shared module.

Hi Graham,

I have not yet looked at Couchbase in detail, but it looks like it is open-source:

Even better, they seem to have a plain Java version as well, not just an Android version, like Realm.

This means that it should be possible to compile their native code and JNI bindings for iOS as well, and then use the same Java APIs as on desktop Java or Android.

Best Regards,

Hi Gergely,

Thanks for the reply. So with the plain Java version of Couchbase Lite, would I add that to the shared project between iOS and Android?

Also, you mention compiling their native code and JNI bindings for iOS, if the plain Java version of Couchbase Lite is added to the shared project will the compilation of the native code and JNI bindings automatically happen when I compile the project? Or is there a separate step I need to do?

Noisyfox, after a while of trial and error it looks like you are correct. I will need to add each one to its corresponding platform and then create an abstract layer. Thanks for the suggestion.

Dear Graham,

for Android, you can add the Android library to your Android module. For iOS, you will need a separate step to build the necessary JNI library for iOS, and copy it to your iOS app. When both platforms have the necessary libraries, you will be able to use the CouchBase Java API from your common module.

Note: you will need to add a CouchBase dependency to the common module, so your IDE knows about these APIs, and then make sure that these dependencies are not transitively included in either Android or iOS, because those modules will already have these dependencies.

Best Regards,

Hi Gergely,

I understand what you are saying about the Android and common modules. I have that part working in my project. What I am confused about is building the necessary JNI library for iOS.

My plan was to follow the steps that other people outlined in this thread:

Are those the correct steps to follow in order to build the JNI library for iOS?

I’m sorry if all this should be obvious but this is my first time doing this kind of thing.

Hi Graham,

no, that topic is about using the Objective-C API of Realm from Java through our Nat/J library. It will work, but you will end up with separate APIs for your database, depending on the platform, and you will need to implement an abstraction layer yourself.

I can’t give you a step-by-step guide on how to compile the JNI library for CouchBase for iOS, because I don’t know the CouchBase project’s build system. But if you do that, you will have a single Java API for CouchBase, that you can use from Android and iOS as well.

We plan to prepare a tutorial on how to do this (and also Realm), but I can’t give you an exact timeline.

If you need this solution quicker, and it is an option for you, we at Migeran provide also commercial consulting and development services around MOE.

Best Regards,