Fixes #281 by porting changes from iOS

https://github.com/couchbase/couchbase-lite-android/issues/281