Kotlin
You can integrate the Ditto SDK into Kotlinprojects to develop native apps for the Android platform.
Following are the minimum requirements that must be met before attempting to install Ditto.
- Android version 6.0 (Marshmallow)
- minSdk version 23.0
- compileSdk version 34.0
- Java Development Kit (JDK) version 11.0
Include the Maven Central repository in your Gradle file, and then synchronize it with your project.
From your project-level build.gradle file located in the app's root directory, ensure the mavenCentral() repository is included in the repositories section:
Synchronize your project with the Gradle file by clicking File > Sync Project with Gradle Files.
Add the Ditto SDK to your app’s build.gradle file in the dependencies block with the appropriate version:
Using the Application-level Context, integrate Ditto into your app's onCreate method.
Most apps require that Ditto run as a singleton. A singleton is an implementation ensuring your Ditto instance accesses and shares a single object instance throughout your app.
To store the Ditto instance as a singleton object, create a custom Application subclass for your Android app. Include the necessary setup configuration below in the onCreate method.
By doing so, you ensure that there is only one instance of Ditto throughout the app's lifecycle, and it remains available for use by any activity or component that needs it. This approach helps in efficient resource management and avoids unnecessary object instantiation and destruction.
Add Ditto to your application by placing it in your Application.onCreate method.
To ensure your app maintains a single Ditto instance throughout its lifetime and prevents it from going out of scope or getting garbage collected, place Ditto in the Application-level Context instead of the Context from any activity where you initially instantiated the Ditto instance.
Replace YOUR_APP_ID and YOUR_PLAYGROUND_TOKEN with your access credentials available from the portal. (See Getting Playground Token Credentials )