Installing Kotlin SDK
You can integrate the Ditto SDK into Kotlin projects to develop native apps for the Android platform.
For a complete overview of the platforms, transports, and devices the Kotlin SDK supports, see Compatibility with Kotlin.
To install the Kotlin SDK and start syncing offline:
Confirm that you meet the minimum requirements. (Prerequisites)
Prepare your environment for Ditto. (Setting Up Your Environment)
Configure your app permissions. (Setting Up Permissions)
Authenticate with the Big Peer and then start syncing offline. (Integrating and Initializing)
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 31.0
- Java Development Kit (JDK) version 11.0
The Ditto Android SDK includes a set of permissions that are required to use all the device features necessary to enable sync. The permissions below will be automatically merged into your app's final manifest.
The tools:targetApi attribute causes the permission to only be requested on devices running the specified API level or higher. This avoids errors in older OS versions that do not recognize the permission.
The android:maxSdkVersion attribute causes permission to only be requested on devices running the specified SDK level or lower. This avoids asking for more permissions than Ditto needs; however, it will prevent your app from being able to request permission on devices running a newer OS version.
To opt out of this behavior and request permission on all OS versions, see the following snippet:
Note that you may need to add the xmlns:tools="http://schemas.android.com/tools" namespace attribute to your app's root <manifest> tag as shown in the AndroidManifest.xml example above.
This will configure your app's build to ignore the android:maxSdkVersion attribute in our SDK allowing the permission to be requested on any SDK version. This technique can be used to tweak any permissions to your liking.
For more details, see the documentation for the Bluetooth and WiFi Aware permissions in the Android Documentation.
The DittoSyncPermissions object requires a Context. You can get the context by invoking getApplicationContext(), getContext(), getBaseContext() or this when in a class that extends from Context, such as the Application, Activity, Service, and IntentService Classes.
Alternatively, requireActivity() is a way to force the code to only work on a Fragment that has a Context.
Add Ditto to your application.
We recommend placing this in your Application.onCreate method. Note that the Context you want to reference here is the Application level Context, rather than whatever Activity you might happen to be instantiating the Ditto instance from initially.
This is because you need to ensure that your app is keeping a single Ditto instance alive for the entire lifetime of the application so it is not going out of scope or getting garbage collected.
Replace YOUR_APP_ID and YOUR_PLAYGROUND_TOKEN with your access credentials available from the portal.
For instructions on how to obtain your access credentials, see Onboarding. For an introduction to authentication in Ditto, see Ditto Basics > Authentication and Initialization.