How to sync data from couchbase server to android app while running android project?

I have ‘todo’ android project and web application. While running andriod project, I insert a todo document into couchbase bucket via php web application. how can i sync todo document into android project (while running android in emulator)?

this is my sync config code
“log”: [""],
“adminInterface”: “”,
“interface”: “”,
“databases”: {
“todo”: {
“server”: “http://admin:test1234@”,
“bucket”: “todo_test_sync”,
“users”: {
“admin”:{“password”:“test1234”, “admin_channels”: ["
“user1”: {“password”: “pass”, “admin_channels”: [“user1”]},
“user2”: {“password”: “pass”, “admin_channels”: [“user2”]}
“sync”: `function(doc, oldDoc)

			if(! || !doc.owner || !doc.type)
			  throw({forbidden: "Missing required properties"});
		   else if(doc.type=='task')
		   else if(doc.type=='task-list.user')
	"shadow": {
             "bucket": "todo_test_bucket"


This is my documents
“name”: “Category”,
“owner”: “user1”,
“type”: “task-list”

“complete”: false,
“createdAt”: 1515491641236,
“task”: “Item”,
“type”: “task”,
“taskList”: {
“id”: “user1.30f8a492-64f9-c1b8-97fc-60f529e73c48”,
“owner”: “user1”

Thank q.

To access Sync Gateway while running in an emulator, you need to use the special address the emulator recognizes to connect to localhost (see for the standard Android emulator).

What versions of Couchbase Lite/Sync Gateway/Couchbase Server are you running?

And of course you need to have a replication active in your Android app.

1 Like

Curious - noticed that you are setting up shadow buckets . What version of platform are you running. Not sure if you are aware, but in Couchbase Server 5.0 / Sync Gateway 1.5, we have shared bucket access. Would it be an option for you to use Couchbase Server 5.0 / Sync Gateway 1.5 if you are not on that ?

Since you specifically mention “emulator”, just to clarify that if you have you sync function and sync gateway set up correctly, it should not matter if your Android app is in the emulator or device. It should sync regardless as long as your Android app is pointing to the sync gateway. I am assuming you are able to push up documents from the app. Use for localhost access from emulator.

The formatting of your sync configuration file is messed up so hard to determine where you have specified the “shadow” property. make sure its at the top level of the config file.

1 Like

Thank q.
I am using
couchbase lite -> 1.3.1
sync gateway -> 1.5.1
couchbase server -> 5.0

Thank you. I am using couchbase lite -> 1.3.1, sync gateway -> 1.5.1, couchbase server -> 5.0 and php 7.1.9. I used url for localhost access from emulator.

Since you are on CBS 5.0 and SGW 1.5.1 can you use shared bucket access as discussed in the link I shared earlier? I would recommend moving away from shadow buckets as its being deprecated.

Remove the “shadow” from the config file and replace as follows

Specifically, from the link

Enabling shared bucket access is simple. You will have to specify a couple of new configuration options in Sync Gateway Config file
– enable_shared_bucket_access to true: This enables Sync Gateway to use XAttrs
– import_docs to continuous: This causes the Sync Gateway to automatically import documents added via the SDK

Deployment Note: In a non-accel SG deployment, only a single SG node should have import_docs=continuous to avoid duplicate processing of documents

Refer to this sample SGW config file for the Todo app that has XAttrs enabled.

This new shared bucket access feature will allow documents pushed into the CBS from your PHP app to sync to the mobile app (via SGW).

Also can you confirm that documents that you push from the Android app reach the couch base server ? the URL is correct.

1 Like

Thank q priya.rajagopal. Now it is working fine :smile: When i push document from the android app reach the CBS and when i updated document in CBS it reach the android app :+1: