Android
Install, initialize, and verify your first event on Android.
Min SDK 21 (Android 5.0) · Target / Compile SDK 34 · Kotlin 2.0+ · AGP 8.7+
Install
Add the dependency to your module-level build.gradle.kts:
dependencies {
implementation("cx.swan:swan-android-sdk:1.0.0")
// Required peer: Firebase Messaging. Wire google-services.json
// and the `com.google.gms.google-services` plugin in your app
// separately — the SDK doesn't bring Firebase in for you.
implementation(platform("com.google.firebase:firebase-bom:33.5.0"))
implementation("com.google.firebase:firebase-messaging")
}Maven Central is enabled by default in settings.gradle.kts for any project
created since Gradle 6.8, but if you've narrowed your repositories make sure
mavenCentral() is in the list.
The SDK declares its own FCM service (SwanMessagingService) in its
manifest (merged automatically into your app's manifest at build time) and
registers the five default notification channels at init — you don't need
to add anything to AndroidManifest.xml.
Initialize
In your Application.onCreate():
import cx.swan.sdk.Swan
import cx.swan.sdk.SwanConfig
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Swan.init(
context = applicationContext,
appId = "your-app-id",
config = SwanConfig(debug = BuildConfig.DEBUG),
)
}
}Swan.init returns immediately (~100 ms). Device registration runs in the
background on its own coroutine. The first call to identify or track will
queue locally and flush as soon as the device is registered.
Dev / staging
The SDK targets the Swan production backend by default. To point at the dev backend during development:
Swan.init(
applicationContext,
appId = "your-app-id",
config = SwanConfig(production = false, debug = true),
)Verify the integration
Six [SwanSDK] * log markers emit at key lifecycle points. Grep logcat for
these to confirm setup:
| Marker | Means |
|---|---|
[SwanSDK] Starting SDK initialization... | Swan.init called |
[SwanSDK] SDK initialization completed successfully | init() resolved |
[SwanSDK] Device registered successfully: <uuid> | Device-register HTTP call succeeded; CDID granted |
[SwanSDK] Foreground notification received: <messageId> | FCM push arrived while app in foreground |
[SwanSDK] Notification displayed successfully with ID: <messageId> | Notification posted to OS |
[SwanSDK] Notification ACK queued | Click ACK queued for backend |
Two markers in the first few seconds (Starting... then Device registered)
means you're live.
Next steps
Track your first event
Screen tracking, custom events, e-commerce helpers.
Identify a user
Sign-in flow, anonymous-to-identified merge, profile enrichment.
Push notifications
FCM wire-up, channels, deep linking from cold-start.
Full API reference
Browse the complete public surface as Dokka HTML — every class, function, and KDoc comment:
The reference is regenerated and pushed on every android/vX.Y.Z release.