Select Page

This post will illustrate all the steps needed to get started with Couchbase Lite in an Android project using Android Studio and the standard Gradle build system. This is the easiest way to get set up to use Couchbase Lite with Android.

Pre-requisites

We assume you have Android Studio already installed and know how to create a new project. See the Android Studio documentation for more details.

If you have Android Studio installed and ready, the estimated time to complete these steps is under 5 minutes.

Step 1

Create a new project (or open a current one). This shows what Android Studio looks like after opening a new “Empty Activity” project.

View at the start of a new project

Step 2

In the Project pane (left-hand navigation area), expand the section entitled “Gradle Scripts”. Double click the build.gradle entry tagged “Module: app”. The arrow in the following image indicates the line to click.

Selecting build.gradle file for editing

You should see the build.gradle file open for editing in the right-hand editor pane.

Step 3

Find the “dependencies” section of the build.gradle file.  It should look something like this.

Add the following line to this section:

The arrow in the following image shows where the entry should be and what the results will look like.

build.gradle detail showing new entry

At this point, you will most likely see a message telling you a project sync may be necessary. Click on “Sync Now”. You can also sync at any time using the toolbar button, as shown next.

Toolbar Gradle sync button

A synch will take a little time. The Android Studio build system (using Gradle) handles downloading all the necessary files and making the necessary changes to your project to include Couchbase Lite.

Start coding!

Once Gradle has finished, you are ready to go. As one quick test, you can see if Android Studio starts including Couchbase Lite in autocompletion suggestions. In the following example, we’ve started to declare a variable of type “Manager”. You can see Android Studio suggests the Manager class from the com.couchbase.lite package as a completion.

AutocompleteCalloutFragment.png

Final notes

This tutorial was created using Couchbase Lite version 1.2.1 and Android Studio version 2.1.2. Some older versions of Android Studio had problems with duplicate manifest files. This will cause Gradle to show an error. If this happens, try adding these lines to the “android” section of the build.gradle:

This post originally appeared on http://blog.couchbase.com/.

Share This