SDK Setup Guides
Kotlin
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 docid\ ka8uws5tc 0kjql4mhau1 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 ) prerequisites 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 setting up your environment confirm that mavencentral() is in the project level build gradle bash allprojects { repositories { mavencentral() } } in the individual module build gradle file bash dependencies { // implementation "live ditto\ ditto 4 +" } setting up permissions the android operating system limits access to some device functionality for end user control and privacy to fully unlock ditto's capabilities, configure your app to automatically request all necessary permissions from end users at runtime android manifest permissions 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 androidmanifest xml \<manifest xmlns\ tools="http //schemas android com/tools" xmlns\ android="http //schemas android com/apk/res/android"> \<uses permission android\ name="android permission bluetooth" android\ maxsdkversion="30" /> \<uses permission android\ name="android permission bluetooth admin" android\ maxsdkversion="30" /> \<uses permission android\ name="android permission bluetooth advertise" tools\ targetapi="s" /> \<uses permission android\ name="android permission bluetooth connect" tools\ targetapi="s" /> \<uses permission android\ name="android permission bluetooth scan" android\ usespermissionflags="neverforlocation" tools\ targetapi="s" /> \<uses permission android\ name="android permission access fine location" android\ maxsdkversion="32" /> \<uses permission android\ name="android permission access coarse location" android\ maxsdkversion="30" /> \<uses permission android\ name="android permission internet" /> \<uses permission android\ name="android permission access wifi state" /> \<uses permission android\ name="android permission access network state" /> \<uses permission android\ name="android permission change network state" /> \<uses permission android\ name="android permission change wifi multicast state" /> \<uses permission android\ name="android permission change wifi state" /> \<uses permission android\ name="android permission nearby wifi devices" android\ usespermissionflags="neverforlocation" tools\ targetapi="tiramisu" /> 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 location permission override \<uses permission android\ name="android permission access fine location" tools\ remove="android\ maxsdkversion" /> \<uses permission android\ name="android permission access coarse location" tools\ remove="android\ maxsdkversion" /> 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 https //developer android com/guide/topics/connectivity/bluetooth/permissions and https //developer android com/guide/topics/connectivity/wifi permissions permissions in the android documentation runtime permissions android requires certain permissions to be explicitly requested by the app to access features like bluetooth low energy (le) and wi fi aware to comply, configure the manifest file for your app to request permissions from end users at runtime to improve the user experience for your app, request all necessary permissions at once by calling the dittosyncpermissions helper in your activity or fragment's oncreate method 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 fun checkpermissions() { val missing = dittosyncpermissions(this) missingpermissions() if (missing isnotempty()) { this requestpermissions(missing, 0) } } alternatively, requireactivity() is a way to force the code to only work on a fragment that has a context fun checkpermissions() { val activity = requireactivity() val missing = dittosyncpermissions(activity) missingpermissions() if (missing isnotempty()) { activity requestpermissions(missing, 0) } } on android, after granting location access, ditto may not immediately recognize the permission, causing a delay in syncing to address this, whenever a relevant permission changes, call refreshpermissions() to quickly check and start syncing with the new permissions override fun onrequestpermissionsresult( requestcode int, permissions array\<out string>, grantresults intarray ) { super onrequestpermissionsresult(requestcode, permissions, grantresults) // regardless of the outcome, tell ditto that permissions maybe changed ditto? refreshpermissions() } for more information about requesting permissions in a user friendly way refer to android's documentation https //developer android com/training/permissions/requesting integrating and initializing 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 try { val androiddependencies = defaultandroiddittodependencies(context) val identity = dittoidentity onlineplayground( androiddependencies, appid = "replace me with your app id", token = "replace me with your playground token" ) dittologger minimumloglevel = dittologlevel debug ditto = ditto(androiddependencies, identity) ditto startsync() } catch (e dittoerror) { log e("ditto error", e message!!) } 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 docid\ jqjyl9gbvsgi9vlw3ywvc for an introduction to authentication in ditto, see ditto basics > docid\ c802c1qiakfga2qxmcywu