Navigation

Set up a MongoDB Mobile Project

Overview

Before you begin coding an Android or iOS app that uses MongoDB Mobile, there are a few short steps required to set up your project. The following sections discuss the prerequisites, and then show you how to prepare your project.

Check Your Environment

To build a Stitch app that uses MongoDB Mobile, you need:

  • Android Studio or another IDE. The steps below have been tested with the latest version of Android Studio.
  • Support for API Level 21 or higher.

We also recommend the following device capabilities:

  • An ARM32, ARM64, or x86_64 device that is running an armeabi-v7a, arm64-v8a, or x86_64 image of Android 5.0 (Lollipop) or later.

Note

MongoDB Mobile does not support x86 devices. By default, Android Studio selects an x86 image for AVD deployments, so if you are deploying your Android app to an AVD, be sure to select an x86_64 image for the AVD. Otherwise, you will see an error message similar to the following:

com.mongodb.embedded.client.MongoClientEmbeddedException: Failed to load the mongodb library: ‘mongo_embedded_capi’. Native library (com/sun/jna/android-x86/libjnidispatch.so) not found in resource path (.)

To build a Stitch app that uses MongoDB Mobile, you need to have Xcode and cocoapods installed. If you do not have cocoapods installed, you can install it from a terminal window with the following commands:

$ sudo gem install cocoapods
$ pod init

Once these prerequisites are met, you are ready to start building your mobile app.

Procedure

To set up a new project that will use MongoDB Mobile, follow these steps:

  1. Open a project in Android Studio, or create a new project. Be sure to set the minimum API level for the project to 21 or higher.

  2. Add the following dependencies to the Module-level Build.gradle file:

    implementation 'org.mongodb:stitch-android-sdk:4.1.0'
    
  3. In the android section of the same Module-level Build.gradle file, add the following compileOptions section:

    compileOptions {
       sourceCompatibility = JavaVersion.VERSION_1_8
       targetCompatibility = JavaVersion.VERSION_1_8
    }
    
  4. Sync the application to incorporate these changes.

  1. Create new project in Xcode, or open an existing project. Set the Language to Swift.

  2. In a terminal window, complete the following steps:

    1. Navigate to the project directory created by Xcode.
    2. If you want to automatically generate the Podfile for a project, run pod init in the directory.
  3. In Xcode, add the necessary the necessary pods to the

    Podfile:

    pod 'StitchSDK', '~> 4.1.0'
    pod 'StitchLocalMongoDBService', '~> 4.1.0'
    
  4. In the terminal window, run pod install to install the pods.

  5. Cocoapods has now created a new .xcworkspace for your project. You should quit the project in XCode and re-open it using this newly-created file. You project now has access to Stitch and MongoDB Mobile.

You can now use the Stitch SDKs to sync data between the local database and Atlas, or work with just the local database (MongoDB Mobile).