Sunday, 13 April 2014

How to use Couchbase Lite with Android

This article should just explain what you need to do in order to use Couchbase Lite in your Android App. It is more or less following the tutorial of the documentation by summarizing it a bit.

So what you need first is an Android project. I used Android Studio (and Gradle as the build framework). The build script is looking as the following one:


Build script

It shows which additional dependencies are required. Additionally you should download the following library and save it under the 'libs' directory of your project


Additional dependency

After you synchronized your Gradle project (All the other additional dependencies will be downloaded from the Maven repositories) you should be able to use the Couchbase Lite classes in your Android application. Let's begin with the Layout definition of our mobile app:

Layout definition

Our example app is just connecting to a database (by creating it) and then stores a document with a specific id. We will then retrieve the document again in order to show some data in a text field. Following the Java code of it:

Main class

The result then looks as the following one:



Couchbase Lite can not just store the local data of your App. The data can be synchronized to a Couchbase Server Cluster. Another blog post will cover this subject.