The SDK in Kotlin Multiplatform

The SDK is a Kotlin Multiplatform library, so a Kotlin Multiplatform project adds it once, to its common code, and reads the configuration with the same Kotlin API on every target: Android, the JVM, iOS, macOS, tvOS, Linux and Windows natively, and the browser with Kotlin/JS or Kotlin/Wasm. The options, the configuration, the gate, the strings, the errors and the push update are on the page of Android and the JVM, which is the same Kotlin API; this page is what changes from one target to the next: the entry point, the files, when the SDK checks, the language and the app type it sends. What the SDK does, what the API key allows and how the SDK behaves offline are on the SDK page.

Install

The SDK is on Maven Central, at version 0.9.0, the same release as on the other platforms:

kotlin {
    sourceSets {
        commonMain.dependencies {
            implementation("cloud.squiddy:squiddy:0.9.0")
        }
    }
}

Gradle picks each target's artifact from the SDK's module metadata, and the common code sees the API every target has: Squiddy, SquiddyOptions, the states, the gate, the strings and the errors. config, gate and strings are StateFlows, so kotlinx-coroutines comes with the SDK. The SDK is built with Kotlin 2.4.21: a project on an older Kotlin may not read its libraries, so use Kotlin 2.4 or later. A project needs only the targets it builds: the SDK does not ask for the others.

The targets

PlatformKotlin targetsEntry pointapp_type sent to SquiddyMinimum
Androidthe Android targetSquiddy.initialize(context, options)androidAPI 24; the app compiles against API 37
JVM: desktop and serverjvmSquiddy.initialize(options, storageDirectory = null), a java.nio.file.PathdesktopJava 17
iOSiosArm64, iosSimulatorArm64, iosX64Squiddy.initialize(options)iosiOS 15
macOSmacosArm64, macosX64Squiddy.initialize(options)desktopmacOS 12
tvOStvosArm64, tvosSimulatorArm64, tvosX64Squiddy.initialize(options)tvostvOS 15
LinuxlinuxX64, linuxArm64Squiddy.initialize(options, storageDirectory = null), a Stringdesktopglibc 2.19 on x64, 2.25 on ARM
WindowsmingwX64Squiddy.initialize(options, storageDirectory = null), a StringdesktopWindows 10, x64
Browser and Node.js, Kotlin/JSjsSquiddy.initialize(options); in Node.js Squiddy.initialize(options, storageDirectory)weba browser with ES modules, fetch and localStorage; Node.js 22.3
Browser, Kotlin/WasmwasmJsSquiddy.initialize(options)weba browser with WebAssembly GC: Chrome 119, Firefox 120, Safari 18.2

The app type is the platform's, never the app's choice, and it is what a configuration's blocks match in appTypes (the format of a configuration): a configuration that has no block for an app type refuses its apps with 5001. The desktop is one app type, desktop, whether the app runs on the JVM or natively, on a Mac, on Linux or on Windows; an Apple TV app has its own, tvos. An app for Apple Vision Pro runs the iOS targets as an iPad app, and sends ios (visionOS). There is no watchOS target yet (watchOS).

macosX64 and tvosX64, the targets of Intel Macs, are deprecated by Kotlin 2.4 for a removal in a later release: the SDK keeps publishing them while Kotlin has them.

Create the instance

Each entry point is the platform's, since Android needs a Context and the JVM, Linux and Windows take the directory of the files, so there is no initialize in the common code: the common code declares a function, and each platform implements it with its own. The entry points are extensions of Squiddy.Companion, imported as cloud.squiddy.sdk.initialize. Create one instance per app and Squiddy environment, and keep it.

// commonMain
expect fun createSquiddy(options: SquiddyOptions): Squiddy

// appleMain: iOS, macOS and tvOS
actual fun createSquiddy(options: SquiddyOptions): Squiddy = Squiddy.initialize(options)

// jvmMain, linuxMain and mingwMain: the default directory of the files, or one of the app's
actual fun createSquiddy(options: SquiddyOptions): Squiddy = Squiddy.initialize(options, storageDirectory = null)

// jsMain and wasmJsMain: a page
actual fun createSquiddy(options: SquiddyOptions): Squiddy = Squiddy.initialize(options)

// androidMain: the application's context, which the Application stores in onCreate
actual fun createSquiddy(options: SquiddyOptions): Squiddy = Squiddy.initialize(applicationContext, options)

The options are common. bundleId is required where the platform has no bundle id to read: on the JVM, on Linux, on Windows, in Node.js, and in a macOS program outside an app bundle; elsewhere the SDK reads the app's own (the package name, the main bundle, the page's host name). On the JVM, Linux and Windows it names the SDK's directory, so it is made of letters, digits, ., - and _, such as com.example.app. initialize checks every option before it creates anything and throws an IllegalArgumentException that names the one to fix; on the JVM, Linux and Windows, an IllegalStateException when it finds no directory for the files and none was chosen.

What changes from one target to the next

TargetFilesWhen the SDK checksLanguage
AndroidnoBackupFilesDir/squiddy, never backed upat start, on every return to the foreground (an activity started)the default locale, followed while the app runs
JVMthe chosen directory, or <bundle id>/squiddy in the user's data directory: Application Support on macOS, %LOCALAPPDATA% on Windows, $XDG_DATA_HOME or ~/.local/share elsewherealways in the foreground: at start, then at the configuration's refreshIntervalthe default locale, read again at every check
iOSLibrary/Application Support/squiddy, out of the backupsat start, on every return to the foregroundthe first preferred language
macOSLibrary/Application Support/<bundle id>/squiddy, out of Time Machineat start, whenever a window becomes visible again (macOS)the first preferred language
tvOSLibrary/Caches/squiddy, which tvOS may purge (tvOS)at start, on every return to the foregroundthe first preferred language
Linuxthe chosen directory, or $XDG_DATA_HOME/<bundle id>/squiddy, or ~/.local/share/<bundle id>/squiddyalways in the foreground, as on the JVMthe locale of the messages: LC_ALL, LC_MESSAGES, then LANG, read again at every check
Windowsthe chosen directory, or %LOCALAPPDATA%\<bundle id>\squiddyalways in the foreground, as on the JVMthe user's display language, read again at every check
Browser, Kotlin/JS and Kotlin/Wasmthe page's localStorage, under keys that start with cloud.squiddy.sdk/at start, whenever the page becomes visible againnavigator.language, followed while the page is open
Node.js, Kotlin/JSthe chosen directory, or the memory of the processalways in the foreground, as on the JVMthe language option, or the process's default locale

On every target the configuration's refreshInterval adds a check at that interval while the app is in the foreground (the periodic check), and refresh() checks at once. Where the app is always in the foreground, those are the only checks after the start, with a change of language through setLanguage and handlePush. The JVM and the native builds of one application, on the same computer, keep the same files in the same directory.

Linux

Windows

The calls go through WinHttp, Windows' own HTTP stack, with the certificates of Windows. The files are in %LOCALAPPDATA%, which a roaming profile does not carry to another computer, and the environment is read in UTF-16, so a profile such as C:\Users\Zoë works. The SDK has one Windows target, mingwX64, for Windows on x64.

The browser: Kotlin/JS and Kotlin/Wasm

A web app written in Kotlin, compiled to JavaScript or to WebAssembly (Compose for Web), uses the same Kotlin API as the other targets, from Maven Central. JavaScript and TypeScript use the npm package instead, with an API written for them: the SDK on the web, which is the same library as the js target.

Push update

pushTopic and handlePush(data) are common, and the push update reaches an app through Firebase Cloud Messaging, which the app receives with Firebase's own SDK for its platform and hands to handlePush: on Android (push update), and on the Apple platforms through APNs (iOS, macOS, tvOS). On the JVM, on Linux, on Windows and in a browser no Firebase message reaches the app, so a change of the configuration arrives at the next check: give their block a refreshInterval if the app must see it while it runs.