Couchbase Mobile brings the power of NoSQL to the edge. It is comprised of three components:
Couchbase Mobile supports flexible deployment models. You can deploy:
Note: This tutorial will require either having an account already set up with Capella, Couchbase Database as a Service (DBaaS) offering or signing up for a free trial. Please see the Sync Gateway version of this learning path for developers looking to learn Couchbase Mobile with Couchbase Server and Sync Gateway via Docker containers.
Before you get started you should take the following prerequisites into consideration:
Android SDK installed and setup (> v.32.0.0)
Android Build Tools (> v.32.0.0)
Android device or emulator running API level 23 (Android 6.0 Marshmallow) or above
JDK 11 (now embedded into Android Studio 4+)
curl HTTP client
Couchbase Capella provides a free 30 day trial of Couchbase cluster, it is the easiest and fastest way to get started with Couchbase. Be up and running in just under 10 minutes with a fully managed database-as-a-service (DBaaS) and 50GB of initial storage and no upfront payment needed. You can try out our N1QL query language (SQL for JSON) for free along with App Services which allows you to sync information between any mobile application and Capella, eliminating database management efforts and reducing overall costs.
You can sign-up for Couchbase Capella following the link below:
Each section of the learning path will walk through a different feature of the demo application. The parts in this learning path build on one another and sometimes show multiple ways to achieve the same results learned, as the Couchbase Lite SDK is very flexible. Once you understand the basics, you can decide which method works best for your team to query the database, return data, and display it for the end-user to interact with on the screen.
The demo application used in this learning path is based on auditing inventory in various warehouses for a fictitious company. Most companies have some inventory - from laptops to office supplies and must audit their stock from time to time. For example, when a user's laptop breaks, the Information Technology department can send out a replacement from the inventory of spare laptops they have on hand.
Users running the mobile app would log into the application to see the projects they are assigned to work on. Then, the user would look at the project to see which warehouse they need to travel to. Once at the warehouse, they would inspect the number of items on hand in stock, tracking them in the mobile application. Finally the data can be synced back to the server for use with other analytical data.
The demo application uses application architecture concepts in developing modern Android applications recommended by the Android development team.
Koin, the popular open-source Kotlin based injection library, is used to manage dependency inversion and injection. ViewModels, Repositories, and Services are all registered using Koin. By using Koin, we can target JDK 11 versus Hilt or Dagger, which requires JDK 8. Koin is also written in Kotlin so it has a more friendly syntax to Kotlin developers.
The application structure is a single Activity that uses JetPack Compose to render the multiple compose-based views. In addition, the Navigation Graph is used to handle routing and navigation between various views.
The Database Manager is a custom class that manages the database state and lifecycle. Querying and updating documents in the database is handled using the repository pattern. ViewModels will query or post updates to the repository and control the state of objects that the compose-based Views can use to display information.
The demo application starts with the
InventoryApplication class, which inherits from the default Application class provided by Android. Koin recommends this structure to set up all the dependencies, including services, repositories, and ViewModels.
MainActivity then defines
setContent, which sets up lifecycle management and creates the navigation controller used to handle navigation in the application. The
InventoryNavGraph function and
MainActions class handles routing between views and sets the start destination to the
LoginView function. Next, the
LoginViewModel uses the mock implementation of the
AuthenticationService interface to test if the user has provided the correct username and password. Finally, the
LoginView uses the
InventoryNavGraph to route the user to the
ProjectListView if they enter the proper credentials. The user can interact with the application in several ways, thus routing the user to different views based on their interactions.
The Audit Inventory Demo app uses JetPack Compose theming engine to offer both light and dark theme versions of the UI. All screen shots provided in the learning path are taken in dark theme. The dark theme is available by selecting dark mode in the Display section of the settings menu of your Android emulator.
Couchbase Lite Key Value Engine with Kotlin and Jetpack Compose
Learn how-to include a Pre-built Database with Kotlin and Jetpack Compose
Learn how-to use Couchbase Lite Batch operations with Kotlin and Jetpack Compose
Learn how-to use Couchbase Lite Query Builder Engine with Kotlin and Jetpack Compose
Learn how-to use Couchbase Lite SQL++ Querying with Kotlin and Jetpack Compose
Learn how-to setup Couchbase Capella and App Services for use with Audit Inventory Demo App
Learn how-to setup Couchbase Lite Replication with Couchbase Capella App Services, Kotlin, and Jetpack Compose