Gradle Logo

Inicio rápido con Couchbase Lite, Android Studio y Gradle

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.

Requisitos previos

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.

Primer paso

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

Paso 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.

Paso 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

Notas finales

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:

Posdata

Consulte más recursos en nuestra portal para desarrolladores y síganos en Twitter @CouchbaseDev. Puede enviar preguntas a nuestro foros. Y participamos activamente en Stack Overflow.

Puede seguirme personalmente en @HodGreeley

Estoy deseando hablar con usted.

Autor

Publicado por Hod Greeley, Defensor del Desarrollador, Couchbase

Hod Greeley es desarrollador de Couchbase y vive en Silicon Valley. Tiene más de dos décadas de experiencia como ingeniero de software y director de ingeniería. Ha trabajado en una variedad de campos de software, incluyendo física computacional y química, seguridad informática y de redes, finanzas y móviles. Antes de unirse a Couchbase en 2016, Hod dirigió las relaciones con desarrolladores para móviles en Samsung. Hod es doctor en física química por la Universidad de Columbia.

Dejar una respuesta