title: How do I sync Couchbase-Lite Android with CouchDB?
body: <p>The problem: During a push I get a "Bad Request" error and some sort of authentication error even though it gets a positive response.</p>
  
  <p>I have almost no experience with CouchDB or Couchbase, but from what I understand you'd usually sync Couchbase-Lite with Couchbase Sync Gateway, but since the latter uses CouchDB's replication protocol you can still use CouchDB as long as you don't use "Channels". Replication with CouchDB is mentioned <a href="http://developer.couchbase.com/mobile/develop/guides/couchbase-lite/native-api/replication/index.html#filtered_pull_couchdb" rel="nofollow">here</a>. I would prefer not to use Couchbase Sync and Couchbase Server since this is a small experimental project for now, I don't need channels and my server has nowhere near enough resources.</p>
  
  <p>I'm using CBL-Android 0.0.0-501 (the most recent one right now I think, already tried 1.0.3) and CouchDB 1.5.0.</p>
  
  <p>This is called in the onCreate method of my main activity on Android:</p>
  
  <pre><code>void minimalPushTest() throws IOException, CouchbaseLiteException {
      String databaseName = "cblpushtest";
      String couchDbUrl = "http://192.168.4.11:5984";
      String userName = "testuser";
      String userPw = "testpw";
  
      // initialize database
      Manager manager = new Manager(new AndroidContext(this), Manager.DEFAULT_OPTIONS);
      Database database = manager.getDatabase(databaseName);
      Document document = database.createDocument();
      Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();
      data.put("somekey", "sometext");
      document.putProperties(data);
  
      // start push replication
      Replication replication = database.createPushReplication(new URL(couchDbUrl));
      replication.setContinuous(false);
      replication.setAuthenticator(new BasicAuthenticator(userName, userPw));
      replication.start();
  }
  </code></pre>
  
  <p>This is what CouchDB says about "/_session" for user "testuser":</p>
  
  <pre><code>{"ok":true,"name":"testuser","roles":["testing"]}
  </code></pre>
  
  <p>...and for "/cblpushtest/_security":</p>
  
  <pre><code>{"admins":{"names":[],"roles":[]},"members":{"names":["testuser"],"roles":["testing"]}}
  </code></pre>
  
  <p>Here is the logcat output in Android Studio:</p>
  
  <pre><code>03-15 23:15:14.999  27429-27429/ W/Sync﹕ [fireTrigger()] =&gt; START
  03-15 23:15:15.109  27429-27429/ W/Sync﹕ [fireTrigger()] =&gt; GO_ONLINE
  03-15 23:15:15.199  27429-27546/ E/Sync﹕ com.couchbase.lite.replicator.ReplicationInternal$4@429cbb20 checkSessionAtPath() response: {ok=true, userCtx={name=testuser, roles=[testing]}, info={authentication_db=_users, authentication_handlers=[oauth, cookie, default], authenticated=default}}
  03-15 23:15:15.309  27429-27546/ W/Sync﹕ com.couchbase.lite.replicator.ReplicationInternal$9@4291cab0: error getting remote checkpoint
  03-15 23:15:15.309  27429-27546/ E/Sync﹕ com.couchbase.lite.replicator.PusherInternal@429c1758: Progress: set error = org.apache.http.client.HttpResponseException: Bad Request
  03-15 23:15:15.309  27429-27546/ W/Sync﹕ [fireTrigger()] =&gt; STOP_GRACEFUL
  03-15 23:15:15.314  27429-27562/ W/Sync﹕ [fireTrigger()] =&gt; WAITING_FOR_CHANGES
  03-15 23:15:15.314  27429-27562/ W/Sync﹕ [fireTrigger()] =&gt; STOP_IMMEDIATE
  </code></pre>
  
  <p>Somehow an "ok=true" response is shown as an error.</p>
  
  <p>And this is couch.log (clocks aren't seem synchronized, but these are the relevant outputs):</p>
  
  <pre><code>[Sun, 15 Mar 2015 22:14:32 GMT] [info] [&lt;0.29026.2&gt;] 192.168.4.61 - - GET /_session 200
  [Sun, 15 Mar 2015 22:14:32 GMT] [info] [&lt;0.29024.2&gt;] 192.168.4.61 - - GET /_local/3e7d908842481392245906438560f235e9d3138f 400
  </code></pre>