Stitch SDK functionality has been moved into the Realm SDKs. Applications using a Stitch SDK can be migrated to the corresponding Realm SDK by using one of the Stitch SDK Migration Guides. Support for the Stitch SDKs will fully end on November 1, 2021.
The official MongoDB Stitch SDK for Android/Java.
The SDK artifacts are hosted by JCenter/Bintray at https://bintray.com/mongodb/MongoDB. Use the jcenter() and mavenCentral()
repositories to get these artifacts.
Add the following to the build.gradle for your app module:
implementation 'org.mongodb:stitch-android-sdk:4.7.0'
Also add the following to your android block in your app module:
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
This will start you off with the core SDK functionality as well as the remote MongoDB service.
For customized dependencies use the following:
implementation 'org.mongodb:stitch-android-core:4.7.0'
implementation 'org.mongodb:stitch-android-services-aws:4.7.0'
implementation 'org.mongodb:stitch-android-services-fcm:4.7.0'
implementation 'org.mongodb:stitch-android-services-http:4.7.0'
implementation 'org.mongodb:stitch-android-services-mongodb-remote:4.7.0'
implementation 'org.mongodb:stitch-android-services-twilio:4.7.0'
For Android applications with ProGuard and minify enabled, the Stitch SDK provides a consumer ProGuard rules file that will automatically be applied when including the SDK.
If you experience any ProGuard related warnings or error when using the Stitch SDK with an application where minify is enabled, try manually adding the rules in android/core/lib-proguard-rules.pro to your application's proguard-rules.pro
file. If that doesn't work, please open an issue on this repository.
Add the following to the build.gradle for your module:
implementation 'org.mongodb:stitch-server-sdk:4.7.0'
This will start you off with the core SDK functionality as well as the remote MongoDB service.
For customized dependencies use the following:
implementation 'org.mongodb:stitch-server-core:4.7.0'
implementation 'org.mongodb:stitch-server-services-aws:4.7.0'
implementation 'org.mongodb:stitch-server-services-fcm:4.7.0'
implementation 'org.mongodb:stitch-server-services-http:4.7.0'
implementation 'org.mongodb:stitch-server-services-mongodb-remote:4.7.0'
implementation 'org.mongodb:stitch-server-services-twilio:4.7.0'
Download and install Android Studio.
Start a new Android Studio project.
In your build.gradle for your app module, add the following to your dependencies block:
implementation 'org.mongodb:stitch-android-sdk:4.7.0'
In your build.gradle for your app module, add the following to your android block:
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
Android Studio will prompt you to sync your changes in your project; hit Sync Now.
libmongo
library, e.g. x86_64
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="stitch_client_app_id">YOUR_APP_ID</string>
</resources>
final StitchAppClient client = Stitch.getDefaultAppClient();
client.getAuth().loginWithCredential(new AnonymousCredential()).addOnCompleteListener(
new OnCompleteListener<StitchUser>() {
@Override
public void onComplete(@NonNull final Task<StitchUser> task) {
if (task.isSuccessful()) {
Log.d("myApp", String.format(
"logged in as user %s with provider %s",
task.getResult().getId(),
task.getResult().getLoggedInProviderType()));
} else {
Log.e("myApp", "failed to log in", task.getException());
}
}
});
Now run your app in Android Studio by going to run, Run 'app'. Use the Android Virtual Device you created previously
Once the app is running, open up Logcat in the bottom of Android studio and you should see the following log message:
logged in as user 5b0483778f25b978044aca76 with provider anon-user
In the case that you don't want a default initialized StitchAppClient by setting up the resource values, you can use the following code once to initialize a client for a given app id that you copied earlier:
final StitchAppClient client = Stitch.initializeAppClient("YOUR_APP_ID");
You can use the client returned there or anywhere else in your app you can use the following:
final StitchAppClient client = Stitch.getAppClient("YOUR_APP_ID");