The SDK on Android and the JVM
Android apps and JVM applications, desktop or server, use the same artifact, cloud.squiddy:squiddy, from Kotlin or from Java. What the SDK does, what the API key allows and how the SDK behaves offline are on the SDK page; this page is the integration.
Install
The SDK is on Maven Central. In Gradle:
repositories {
mavenCentral()
}
dependencies {
implementation("cloud.squiddy:squiddy:0.9.0")
}
Gradle picks the platform's artifact from the SDK's module metadata: squiddy-android, an AAR, or squiddy-jvm, a JAR. A Maven build names it itself, for example cloud.squiddy:squiddy-jvm:0.9.0. A Kotlin Multiplatform project adds the same dependency to commonMain: Kotlin Multiplatform has every target, from iOS to Linux and Kotlin/Wasm. Every artifact comes with its sources and its API reference (-javadoc.jar), and is signed.
| Android | JVM | |
|---|---|---|
| Minimum | minSdk 24, and the app compiles against API 37 or later, which OkHttp 5.5 requires: the AAR states it, and an older compileSdk fails the build naming the SDK | Java 17 |
| What it adds to the app | the INTERNET permission, nothing else; OkHttp adds its own androidx.startup initializer, which stores the application context | — |
| R8 | no rule to write: the AAR carries what it needs | — |
app_type sent to Squiddy | android | desktop |
| Bundle id | the package name | the bundleId option, required |
| Files | noBackupFilesDir/squiddy, never backed up | <bundle id>/squiddy in the user's data directory: Application Support on macOS, %LOCALAPPDATA% on Windows, $XDG_DATA_HOME or ~/.local/share elsewhere; or a directory the application chooses |
Keep the key out of the repository
The key ends up inside the app, so it is not a secret (see the API key), but like any credential it does not belong in the repository. On Android, put it in local.properties, which git ignores, and hand it to the code through BuildConfig:
# local.properties: never committed
squiddy.apiKey=sqd_…
// app/build.gradle.kts
val localProperties = java.util.Properties().apply {
val file = rootProject.file("local.properties")
if (file.isFile) file.inputStream().use(::load)
}
android {
buildFeatures {
buildConfig = true
}
defaultConfig {
buildConfigField("String", "SQUIDDY_API_KEY", "\"${localProperties.getProperty("squiddy.apiKey", "")}\"")
}
}
A pipeline writes the same line into local.properties from a secret variable before it builds. A JVM application reads its key from the environment or from its own configuration file.
Initialize
Create one instance per app and Squiddy environment, when the app starts, and keep it: there is no global instance and no automatic start. On Android the place is Application.onCreate:
import android.app.Application
import cloud.squiddy.sdk.Squiddy
import cloud.squiddy.sdk.SquiddyOptions
import cloud.squiddy.sdk.initialize
class App : Application() {
lateinit var squiddy: Squiddy
private set
override fun onCreate() {
super.onCreate()
squiddy = Squiddy.initialize(
this,
SquiddyOptions(
host = "https://squiddy.example.com",
apiKey = BuildConfig.SQUIDDY_API_KEY,
appId = "my-app",
appVersion = "2026.11.19", // YYYY.MM.DD: Squiddy compares it as a number
appMode = if (BuildConfig.DEBUG) "debug" else "release",
),
)
}
}
On the JVM there is no context, and the bundle id is required:
val squiddy = Squiddy.initialize(
SquiddyOptions(
host = "https://squiddy.example.com",
apiKey = System.getenv("SQUIDDY_API_KEY"),
appId = "my-app",
appVersion = "2026.11.19",
appMode = "release",
bundleId = "com.example.desktop", // names the data directory: letters, digits, '.', '-', '_'
),
// storageDirectory = Path.of(…) to choose the directory yourself
)
initialize checks every option before it creates anything and throws an IllegalArgumentException that names the one to fix: an empty key, a version that is not YYYY.MM.DD, a negative push refresh jitter. On the JVM it throws an IllegalStateException when it cannot find a data directory and none was chosen. It returns at once and touches no file on the calling thread, so it may run on the main thread under StrictMode: the SDK reads and writes its files on its own threads, and config stays Pending until the stored configuration is read. close() stops the updates and releases the network client; an Android app usually keeps its instance for the life of the process.
From Java
Java builds the options with SquiddyOptionsBuilder, which takes the five required options and has a method for each of the others, with java.time.Duration for the durations. Each platform has a static entry point:
import cloud.squiddy.sdk.*;
import java.time.Duration;
SquiddyOptions options = new SquiddyOptionsBuilder(
"https://squiddy.example.com", System.getenv("SQUIDDY_API_KEY"), "my-app", "2026.11.19", "release")
.bundleId("com.example.desktop") // required on the JVM; Android reads the package name
.timeout(Duration.ofSeconds(20)) // every method is optional
.build();
Squiddy squiddy = SquiddyJvm.initialize(options); // or (options, storageDirectory)
// Squiddy squiddy = SquiddyAndroid.initialize(context, options); // Android
On Android below API 26, java.time.Duration needs core library desugaring, as any use of java.time does; the rest of the Java API works from API 24.
Options
| Option | Default | What it does |
|---|---|---|
host, apiKey, appId, appVersion, appMode | — | Required. appVersion is YYYY.MM.DD; appMode is matched against the configuration's modes, such as debug and release |
customParams | none | The custom parameters the configuration's rules match, sent as given |
bundleId | the package name on Android | Required on the JVM |
language | the user's | A language of the app's own, sent as given; setLanguage changes it later |
entityId | the installation id | An opaque id of yours that rollouts place the client by (see rollouts) |
timeout | 10 seconds | The longest one call may take |
pushRefreshJitter | 60 seconds | The longest random wait before the check a push update asks for; zero or more |
logger | none | A SquiddyLogger receiving DEBUG lines (the HTTP headers, the key redacted) and WARNING lines (problems the SDK recovered from) |
How often the SDK checks while the app stays in the foreground is not an option: the configuration decides it, and by default there is no periodic check. The periodic check says how, and how the calls of the installations count against the key's limit.
The configuration
config is a StateFlow<SquiddyState>:
squiddy.config.collect { state ->
when (state) {
SquiddyState.Pending -> showSplash()
is SquiddyState.Ready -> apply(state.configuration) // state.origin: CACHE or NETWORK
is SquiddyState.Failed -> state.configuration?.let(::apply) // the last valid one; state.error says why
}
}
val timeout = squiddy.config.value.configuration?.serverApi?.setting("timeout")?.asInt()
Ready comes CACHE from the device and NETWORK once Squiddy sent or confirmed it; a check that finds the configuration unchanged emits nothing. A RemoteConfiguration has its version, its serverApi (base URL, mode, API version, debug flag and settings), its two notices appUpdate and infoPoint, and its strings. A setting reads as text with value, or as asInt(), asDouble() and asBoolean(), which parse the value and throw a SettingTypeException naming the setting when it is not of that type.
In Compose, collect it with the lifecycle: val state by squiddy.config.collectAsStateWithLifecycle(). From Java, addConfigListener calls a listener with the value now and with every change, on a thread of the SDK, until cancel() of the SquiddyObservation it returns; an Android app hands the value to the main thread. squiddy.getConfig().getValue() reads it without a listener.
The gate
gate is a StateFlow<AppGate> derived from the configuration, and says which screen the app shows:
squiddy.gate.collect { gate ->
when (gate) {
AppGate.None -> showApp()
is AppGate.UpdateRequired -> showUpdateScreen(gate.title, gate.message)
is AppGate.Maintenance -> showMaintenanceScreen(gate.title, gate.message)
}
}
UpdateRequired comes from an app-update notice marked as required for this version, Maintenance from an info-point notice that halts the app, and when both apply maintenance wins. Titles and messages arrive already localized by Squiddy; a title or a message left blank for the language arrives empty, and the gate applies all the same. The gate holds for the configuration read from the device too, so a maintenance stays on screen offline, and it is None while there is no configuration at all. The notices stay readable one by one, with their flags, in configuration.appUpdate (isRequired) and configuration.infoPoint (isHalting): a notice without its flag is an update the app may suggest, or an information that does not stop it. From Java, addGateListener.
Strings
val title = squiddy.string("welcome_title", fallback = "Welcome")
squiddy.strings.collect { strings -> render(strings.string("welcome_title", "Welcome")) }
A string is looked up in the language the SDK asks in, then in the configuration's default language, then fallback (string(key) without one returns null), and only a key the language does not have goes on to the next. From SDK 0.4.0 an empty text is a text: a translation left blank in the dashboard is returned empty, with or without fallback, so a key left blank in a language stays blank in the app. Up to 0.3.0 the SDK skipped an empty text and fell back to the default language. The configuration holds every language its API block supports, so a change of language changes the strings at once, without a call.
Language
The SDK asks Squiddy in the primary language of the default locale (it for it-IT), and follows it: on Android a change of the system language or of the app's own language, set by the user or with LocaleManager.setApplicationLocales, reaches it while the app runs, and the JVM reads the locale again at every check. An app with its own language picker calls squiddy.setLanguage("en"), and setLanguage(null) goes back to the user's. When the language changes, the strings switch at once, and the SDK checks with Squiddy, in the foreground, for the texts of the notices, which Squiddy localizes for each call.
When the SDK checks
At every start, after serving the stored configuration; whenever the app comes back to the foreground; and, if the API block of the configuration has a refreshInterval, at that interval while it stays there (the periodic check). On Android the app is in the foreground while one of its activities is started. The JVM is always in the foreground, so a desktop or server application checks at the configuration's interval while the instance is open; without one, it checks only at start-up, on refresh(), on handlePush and when setLanguage changes the language. squiddy.refresh() checks at once, in the background too, and the outcome arrives in config.
Errors
A failed check is a Failed state carrying a SquiddyError, a sealed class: the table of errors says what each one means.
val failure = (squiddy.config.value as? SquiddyState.Failed)?.error
when (failure) {
is SquiddyError.TenantSuspended -> tellSomeone()
is SquiddyError.RateLimited -> log("Squiddy calls again in ${failure.retryAfter}")
else -> Unit
}
From Java, failed.getError() instanceof SquiddyError.RateLimited, and SquiddyErrors.retryAfter(rateLimited) gives the wait as a java.time.Duration, or null.
Push update
Push update is a button on each configuration in the dashboard: Squiddy sends a data-only message of Firebase Cloud Messaging to the configuration's topic, and every installation subscribed to it checks within a random wait of up to pushRefreshJitter, also in the background. The SDK does not depend on Firebase: the app subscribes to the topic the SDK gives it and passes the messages it receives to the SDK.
What it takes:
- A Firebase project with the Android app, registered with its application id. Its
google-services.jsongoes into the app module, with thecom.google.gms.google-servicesGradle plugin andcom.google.firebase:firebase-messagingas dependencies. A device needs Google Play services to receive the messages. - The project's service account key, uploaded to Squiddy. In the Firebase console, Project settings → Service accounts → Generate new private key gives a JSON file. Whoever manages the configuration uploads it in the dashboard, on the configuration's Push update tab, where Squiddy checks it with Google before keeping it, encrypted. The credential belongs to one configuration, that is one app in one environment, so staging and production can use different Firebase projects. Keep the file out of every repository.
- The subscription and the message, in the app:
// After initialize, at every start: subscribing again is harmless.
FirebaseMessaging.getInstance().subscribeToTopic(squiddy.pushTopic)
class AppMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(message: RemoteMessage) {
val squiddy = (application as App).squiddy
if (squiddy.handlePush(message.data)) return // Squiddy's: the SDK checks within pushRefreshJitter
// the app's own messages
}
}
<!-- AndroidManifest.xml, inside <application> -->
<service android:name=".AppMessagingService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
handlePush returns true for Squiddy's message, whose data says squiddy = refresh and names its topic in squiddy_topic, and false for any other, which stays the app's. Squiddy sends it with high priority, so onMessageReceived runs in the background too. From Java: squiddy.getPushTopic() and squiddy.handlePush(message.getData()).
The topic is squiddy- and 64 hexadecimal digits, computed from the API key and the appId: every installation that reads the same configuration with the same key shares it, and Squiddy notifies the topic of every active key of the environment, so installations still on an older key are reached too. A version of the app with another key has another topic: keep the topic you subscribed to and, when pushTopic differs, unsubscribe from the old one.
The random wait spreads the calls: Squiddy notifies every installation at the same moment, and they all call with one key, whose calls a minute the plan limits. A notification never hastens a retry after a failure, makes no call after Unauthenticated, and a burst of notifications costs one call.
Checking that it works. The dashboard reports whether Firebase accepted the message for each active key; accepted is not delivered. With a logger, an installation that receives the message logs, at DEBUG, "Squiddy asked for an update: checking the configuration in …", and the call follows within the wait.