Couch base lite Java API for IOS and Android which can be used in codenameone framework


We are evaluating codenameone framework based on java to build cross platform application for IOS and Android. I saw the documentation of Java API and there is a specific version for Android and there core which can be used in any other Java project. I tried to look at the couchbase-lite-java-core classes I could see some pkgs are used which are not supported in codenameone framework? Is there any way I can use couchbase lite in codenameone framework?
Aravinda T


It seems like you have answered your own question.

I could see some pkgs are used which are not supported in codenameone framework


We are using some Android-specific packages, as you’ve noticed. To make CBL cross-platform we would need to adapt our code to support pure Java (or at least cross platform) equivalents of those packages.

We’ve generally had very low demand for a pure Java or desktop-Java CBL, so this wasn’t a priority for 2.0.

(Also: I’m skeptical about running Java apps on iOS. The runtime will be pretty large, and since iOS apps aren’t allowed to run JITs, performance will be poor.)


Codename One is native. So naive Android code can be embedded just fine it will only work on Android. The same is true for iOS code.

On iOS the VM translates bytecode to C and compiles it using xcode for iOS so the performance is native. We removed a lot of Java’s “problematic” features (e.g. reflection) that would hinder performance and balloon the size so an iOS Codename One app can be as small as 3mb.

As I explained in our discussion forum this would mostly be a matter of wrapping the native libraries in native interfaces. That’s our equivalent of JNI that is more adaptable to the mobile world. It works with Objective-c, Android’s Java flavor, C#, JavaScript etc.


Interesting! Take a look at LiteCore, the native library that provides the core CBL functionality. You can build a wrapper around its C API.


A more natural approach would be to just use the iOS & Android ports as is & abstract them with a high level API similar to the Android API. We essentially create a thin layer on top of the existing native implementations.


The Java and Obj-C/Swift APIs are already wrappers around LiteCore. So you’d be building wrappers around wrappers. But that might end up being easier; you’d have to try it out.


I went and read about this. I think the confusion here is around the term “native interfaces”. To CodenameOne this means "interfaces to the native langauge for the platform (i.e. Java for Android, Objective-C for iOS, etc) as opposed to pure Java that the actual CodenameOne library logic is written in. I watched the video on the subject and it seems like they are using JNI-like conventions to be able to call from Java to platform specific methods in the platforms language. So their “interface” is a bunch of specially named methods that their toolchain can detect and write calls to.


Yep. It makes it more natural to work with the iOS API as things such as the native OS frameworks or 3rd party libraries can be easily integrated like you would in xcode.

It also makes it possible to use Android’s full feature set when running on that platform without compromising the portability of the rest of the code.

I’m pretty busy right now but I might take a stab at wrapping this in May.