Why Couchbase is difficult to use?

I’m trying to develop an android application with couchbase.

I can get through a firebase demo in several ten minutes according to some official document. It’s unlucky, i can’t get through couchbase. couchbase is not easy to use.

I post my repo here, If anyone can help me finger it out. will be appreciated.

Hello,

Thank you for reaching out to us. We are looking into the issue and will provide you with updates as soon as possible.

Thanks,
Harshini

1 Like

Hello,

From the GitHub, we see that you are using JAVA SDK for building your application.
Please find the below documentation links helpful for developing an Android Application using Couchbase:
https://docs.couchbase.com/couchbase-lite/current/android/quickstart.html
https://docs.couchbase.com/tutorials/quick-start/quickstart-java3-native-intellij-firstquery-cb65.html

If you are getting any error while connecting to Couchbase Server, please provide the details related to that error. We would be happy to troubleshoot further.

Thank you
Navya M S

1 Like

Hi @Nemo_Ang
I’m sorry you’re having some difficulties getting up and running and I hope the links above from Navya help you get going. If not then please let us know what specific problem you are seeing and we will try to help.
I just wanted to let you know that I was scanning your sample repo and found a number of leaked security details in the code, including a cluster password and what looks like AWS access and secret keys, so I’d recommend completely deleting the repo for security reasons.

1 Like

Hi graham,
thanks,
if you try to debug the code, I think you will get the same crash as i got.

line 119
Cluster cluster = Cluster.connect(endpoint, ClusterOptions.clusterOptions(username, password).environment(env));

endpoint, username, password and env are all correct, just don’t know why i can’t get the cluster.

Well, I won’t be able to connect to your cluster as I won’t be on your whitelisted IPs. I did check out the code and it looks fine (it’s the Java SDK getting started example I believe?) and compiles. Could you copy the stacktrace or error that you’re seeing? You may also want to double-check that the cluster certificate is correct, and that you’ve whitelisted your IP in the Capella UI. You can try uncommenting the ‘.trustManagerFactory(InsecureTrustManagerFactory.INSTANCE)’ line temporarily. This will disable certification verification so it’s insecure, but it will tell you if the problem is with the certificate. The SDK Capella troubleshooting connection guide may be useful to you too.

1 Like

Hi graham,

Finally, i got some time to get into it.

And i set 0.0.0.0/32 into the IP whitelist.

even i disable the Tls: still got error as below:

I/PlatformDependent: Your platform does not provide complete low-level API for accessing direct buffers reliably. Unless explicitly requested, heap buffer will always be preferred to avoid potential system instability.
E/e.democouchbas: No implementation found for int com.couchbase.client.core.deps.io.netty.channel.epoll.Native.offsetofEpollData() (tried Java_com_couchbase_client_core_deps_io_netty_channel_epoll_Native_offsetofEpollData and Java_com_couchbase_client_core_deps_io_netty_channel_epoll_Native_offsetofEpollData__)
E/e.democouchbas: No implementation found for int com.couchbase.client.core.deps.io.netty.channel.kqueue.Native.sizeofKEvent() (tried Java_com_couchbase_client_core_deps_io_netty_channel_kqueue_Native_sizeofKEvent and Java_com_couchbase_client_core_deps_io_netty_channel_kqueue_Native_sizeofKEvent__)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.democouchbase, PID: 5711
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/NameNotFoundException;
at com.couchbase.client.core.util.ConnectionStringUtil.seedNodesFromConnectionString(ConnectionStringUtil.java:82)
at com.couchbase.client.java.AsyncCluster.seedNodesFromConnectionString(AsyncCluster.java:228)
at com.couchbase.client.java.Cluster.connect(Cluster.java:259)
at com.example.democouchbase.MainActivity.onCreate(MainActivity.java:119)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn’t find class “javax.naming.NameNotFoundException” on path: DexPathList[[zip file “/data/app/com.example.democouchbase-q6O8XMZwKM-0mRSAnGMVhw==/base.apk”],nativeLibraryDirectories=[/data/app/com.example.democouchbase-q6O8XMZwKM-0mRSAnGMVhw==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.couchbase.client.core.util.ConnectionStringUtil.seedNodesFromConnectionString(ConnectionStringUtil.java:82)
at com.couchbase.client.java.AsyncCluster.seedNodesFromConnectionString(AsyncCluster.java:228)
at com.couchbase.client.java.Cluster.connect(Cluster.java:259)
at com.example.democouchbase.MainActivity.onCreate(MainActivity.java:119)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I/Process: Sending signal. PID: 5711 SIG: 9

Hi @Nemo_Ang. Ok, there look to be a couple of issues here from running the Java SDK directly from Android. But now I think about this more, this is not a tested configuration as it’s very unusual for an Android app to be accessing a remote database directly in this way, no? I’m not a mobile developer so this is outside of my wheelhouse, but I think usually you’d either want to use Couchbase Lite (e.g. a local database that syncs with a remote), or you’d want to access a remote backend server (something you’d write) that would connect to the database. Connecting directly to a remote database would seem to involve the same security issues you’d have if you connected directly from a frontend web application to a remote database, which is why this is rarely (probably never) done.

If you do want to proceed with trying to access Couchbase directly from the app using the SDK, here’s a couple of suggestions to get you past your current problem. But as above this isn’t a tested configuration so I can’t guarantee you won’t hit further issues:

  • The warnings of “Your platform does not provide complete low-level API for accessing direct buffers reliably” and ones related to epoll and kqueue can be ignored. They indicate that certain low-level network and memory APIs aren’t available on Android. Less-performant alternatives will be selected.
  • The “java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/NameNotFoundException” error is the current blocker. Looks like Android’s JVM does not have a class we use (NameNotFoundException). This code is only checked if DNS-SRV is enabled. Usually DNS-SRV is required for using Couchbase Capella, but you could try disabling it, and using nslookup to find the hostnames to connect to.

For finding the nslookup syntax please see this guide.
And the client settings tells you how to disable DNS-SRV in the SDK.

I hope that helps.

1 Like

Hi graham,

Thank you. frankly speaking, i’m a newby of mobile developer. after disabl the DNS-SRV, It seems much better, but it still crashed.

and there is no NameNotFoundException anymore. the new issue is:

Caused by: java.net.SocketException: Permission denied

I double checked the certificate, no issue, if you clone the repo which i just pushed. the nemowangv2 is for all buckets, all scopes and read/write

not sure we are close to fix it.

part of the stack as below:

 Caused by: java.net.SocketException: Permission denied
    at sun.nio.ch.Net.socket0(Native Method)
    at sun.nio.ch.Net.socket(Net.java:420)
    at sun.nio.ch.Net.socket(Net.java:413)
    at sun.nio.ch.SocketChannelImpl.<init>(SocketChannelImpl.java:130)
    at sun.nio.ch.SelectorProviderImpl.openSocketChannel(SelectorProviderImpl.java:60)
    at java.lang.reflect.Constructor.newInstance0(Native Method) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 
    at com.couchbase.client.core.endpoint.BaseEndpoint.lambda$reconnect$1$com-couchbase-client-core-endpoint-BaseEndpoint(BaseEndpoint.java:336) 
    at com.couchbase.client.core.endpoint.BaseEndpoint$$ExternalSyntheticLambda3.get(Unknown Source:6) 
    at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44) 
    at reactor.core.publisher.InternalMonoOperator.subscribe(InternalMonoOperator.java:64) 
    at reactor.core.publisher.FluxRetryWhen$RetryWhenMainSubscriber.resubscribe(FluxRetryWhen.java:216) 
    at reactor.core.publisher.FluxRetryWhen$RetryWhenOtherSubscriber.onNext(FluxRetryWhen.java:269) 
    at reactor.core.publisher.FluxConcatMap$ConcatMapImmediate.innerNext(FluxConcatMap.java:282) 
    at reactor.core.publisher.FluxConcatMap$ConcatMapInner.onNext(FluxConcatMap.java:861) 
    at reactor.core.publisher.MonoDelay$MonoDelayRunnable.propagateDelay(MonoDelay.java:271) 
    at reactor.core.publisher.MonoDelay$MonoDelayRunnable.run(MonoDelay.java:286) 
    at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68) 
    at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
    at java.lang.Thread.run(Thread.java:764)

HI @Nemo_Ang , I searched around this error a bit, and it looks like you need the android.permission.INTERNET permission in your manifest. Please see this StackOverflow post for details.
Did you have any thoughts on my comments above about instead going down the route of Couchbase Lite or connecting to a backend server?

1 Like

Hi graham,

yeah yeah, can’t believe i ignore this. will try it… thanks.

and for your question. I guess we can get through it. if firebase works on android. couchbase also should be. when I get the conclusion that this route doesn’t work. then i will try other route.

Hi graham,

I added internet access permission

but it still doesn’t work, the new issue is:

java.net.UnknownHostException: Unable to resolve host “cb.zfvly6tw3my8zbey.cloud.couchbase.com”: No address associated with hostname

so, i tried using

to ping cb.zfvly6tw3my8zbey.cloud.couchbase.com
the webpage says: Invalid host name or IP address.

but cloud.couchbase.com wroks.

Hi @Nemo_Ang

Ah well you are hitting what I was getting at in my previous post when I was talking about disabling DNS-SRV. Since you’ve had to disable DNS-SRV in the SDK, you need to do the DNS-SRV lookup manually, which you can do with nslookup using the syntax from that guide I linked. Basically this:

nslookup -q=SRV _couchbases._tcp.cb.zfvly6tw3my8zbey.cloud.couchbase.com 8.8.8.8
Server:  dns.google
Address:  8.8.8.8

Non-authoritative answer:
_couchbases._tcp.cb.zfvly6tw3my8zbey.cloud.couchbase.com        SRV service location:
          priority       = 0
          weight         = 0
          port           = 11207
          svr hostname   = 5oguqlaef7xw5hja.zfvly6tw3my8zbey.cloud.couchbase.com

E.g. 5oguqlaef7xw5hja.zfvly6tw3my8zbey.cloud.couchbase.com should be your hostname. But I don’t know how often this changes, e.g. how safe it is to bypass DNS-SRV in this way and hardcode this hostname in your app, so you may want to do this lookup dynamically regularly. Perhaps the Capella team can advise on how often the DNS-SRV record may change.