- Stitch >
- MongoDB Mobile >
- Usage Guides
Set up a MongoDB Mobile Project¶
On this page
Deprecation
MongoDB has deprecated MongoDB Mobile. We are focusing our efforts on Realm, the most popular database for mobile devices.
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¶
- Android (Java) SDK
- iOS (Swift) SDK
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
, orx86_64
image of Android 5.0 (Lollipop) or later.
Supported Device Architectures
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:
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:
- Android (Java) SDK
- iOS (Swift) SDK
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.Add the following dependencies to the Module-level Build.gradle file:
In the
android
section of the same Module-level Build.gradle file, add the followingcompileOptions
section:Sync the application to incorporate these changes.
Create new project in Xcode, or open an existing project. Set the Language to
Swift
.In a terminal window, navigate to the project directory created by Xcode, and run the following command to automatically generate a Podfile:
In Xcode, add the necessary the necessary pods to the
Podfile
:In the terminal window, run the following commands:
The
pod install
command creates a new XCode.xcworkspace
file for your project that includes the dependencies listed in the Podfile.Quit XCode, and then re-open the project using the newly-created
.xcworkspace
file.
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).