I want to query Couchbase Server views from an Android application. Is this possible to do so with the Java SDK?
When I included the “compile ‘com.couchbase.client:java-client:2.0.2’” dependency in my gradle build, it compiles, but there are ClassNotFoundExceptions at runtime.
I’m aware of Couchbase-lite, but that appears to a be a client for the mobile storage only.
It may be possible, but Android is not an intended platform at this time. The CNFE is likely related to dependencies from netty to java NIO?
Your best bet is probably to set up a small web service with something like spring boot to do such queries. Of course, if you want the best user experience, we recommend getting that data to the device for local querying. Doing it remotely is probably okay if it’s limited and you handle it well in your app.
One other project that could work for this is Ektorp against Sync Gateway. I don’t know status on its Android support.
Thanks for your quick reply.
Yes, I am the process of building REST services on the backend. I got anxious to pull some data from Couchbase into my mobile app and tried connecting to it directly. Time to reprioritize
The actual exception seemed JMX (not supported by the VM on Android) related:
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory;
It’d be going down the ‘unsupported’ path, but that could probably be cut out of there. It’s diagnostics related, as you can see. The other path is well traveled though.
right, this is most likely because the Android JDK is not exposing all features that are part of the java* namespace, which we expect to be in place.
Currently, you’d probably need to remove the diagnostics part and run your own build - in theory that can work. Both Netty and RxJava support Android as far as I know, and with some work we could make the client Android compatible too. But you’re the first one requesting it, and since we have Couchbase Lite (for both android and a general java version) I’m not sure thats a path we’re planning to investigate.
Side not: we love contributions though! So if you make it work and submit pull requests, I’d love to review them.
I threw together a service with the Python SDK + Flask-restful. Never used Flask before (so I’m not sure it is a good long-term solution) but it was quite simple to use and got the job done quickly. I might like to try Clojure; I see there is a community supported SDK.
@bdiegel the clojure SDK is based on the couchbase java client 1.* series. We also added the Diagnostics info there in recent releases, so if it points to older ones it might work. Note that the old one also has never been tested against Android.
This thread was created almost 2 year ago, I was wondering what’s the answer to the original question (Which SDK for Android app querying CB Server?) now? I am using couchbase mobile (CBLite+sync_gateway+CB Server ) writing an android mobile app that need to make relatively frequent query to couchbase server, what’s the easiest solution to this now? Are the contents in online training course “CB130j Intro to NoSQL Development (Java)” useful for making query from android mobile device directly to couchbase server? Thanks!
Couchbase Lite + Sync Gateway + Couchbase Server is designed as a mobile application stack. Direct access to Couchbase Server is not.
If you have a mobile app that may run over a slow network, or go offline, you should really be looking at using the mobile stack.
Can you explain more about your use case?
I find myself asking the same questions as lordofming, so maybe I can answer from my perspective / use case.
So far I’ve setup a service which continuously writes time series data to couchbase server and I’d like to send this data through to a mobile application. I originally thought that this was the use case for sync gateway (to sync a couchbase server db through sync gateway to one or more couchbase lite dbs). However from what I’ve been reading it seems that I should instead be performing all server side interactions with sync gateway itself, through the REST API (instead of directly with couchbase server through eg. the python sdk).
The issue is that the REST API doesn’t seem to support some of the functionality (eg subdoc mutate_in) which i’m using heavily for writing the time series data to couchbase server.
So then I thought I could just skip the full mobile stack and connect the mobile app directly to couchbase server, implementing a local data model for the time series as an array in the app and syncing it with couchbase server via the java sdk… but now as i learn it’s unsupported, i get the feeling that I’m trying to do the wrong thing again.
It’s safe to say I’m pretty new at this… But I’d be very interested to know if others have the same use case as me and if there’s a simpler more obvious way i could reach a solution.
@benson the reason we don’t support the Java SDK for Couchbase Server for mobile is because the SDKs are written with some strong assumptions about network behavior that won’t hold.
Time series data can be a little tricky. I’m guessing you don’t want the entire dataset moved down to your mobile app?