You can integrate the Ditto SDK into Kotlin projects to develop native apps for the Android platform.
minSdk
version 24.0compileSdk
version 34.0build.gradle
file located in the app’s root directory, ensure the mavenCentral()
repository is included in the repositories
section:build.gradle
file in the dependencies
block with the appropriate version:
AndroidManifest.xml
includes all of the necessary permissions for enabling its mesh network capabilities. These permissions will automatically be merged with your app’s permissions, so you should be aware of them.
android:maxSdkVersion
attribute which means they are not used on devices running newer versions of Android. This is a best practice to respect users’ privacy when those permissions are not necessary.
However, some apps may still need to use one or more of the above permissions across more versions of Android. This can be accomplished by overriding the permission configuration in your app’s AndroidManifest.xml
To override any of these permission limitations in your app, do the following:
<manifest>
tag, just before the <application>
tag, add the relevant permissions you want to configure (location example):tools:remove
attribute. This tells the manifest merger to selectively remove the android:maxSdkVersion
behavior from the associated permissions, changing them to apply to all Android versions.DittoSyncPermissions
helper class:
DittoSyncPermissions
helper class in the main activity of your app:onCreate
method:refreshPermissions()
to quickly check and start syncing with the new permissions. This can be done in the onRequestPermissionsResult()
activity lifecycle method: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.
Application.onCreate
method.Context
instead of the Context
from any activity where you initially instantiated the Ditto instance.YOUR_APP_ID
and YOUR_PLAYGROUND_TOKEN
with your access credentials available from the portal. (See Getting SDK Connection Details )keep class com.ditto.kotlin.internal.swig.ffi.**
ensures that all classes and interfaces under the com.ditto.internal.swig.ffi package (including sub-packages) are retained.{ *; }
specifies that all members (fields, methods, constructors, etc.) of these classes should be preserved as well.AndroidManifest.xml
:
small_app_icon
drawable must be monochrome white.
The foreground service will be automatically started and stopped on startSync()
and stopSync()
, respectively.
For more information about the Ditto foreground service consult the API Reference.
Setup
Check crash collection
DittoExperimental.triggerTestPanic()
function to do so. At this point, without native symbols, the crash will be unreadable. If you are not seeing any crashes in the reporter, check that you have integrated its components correctly.Upload symbols
.so
file provided by the Ditto SDK for the platform you are targeting. This file contains a symbol map allowing crashes to be symbolicated.The native library .so
can be found at the following path:Final test