Android Kotlin SDK
Kotlin/Android quickstart for com.layers.amba:amba-sdk-android — Maven Central install, Amba.configure(Application), tokens via EncryptedSharedPreferences, Google sign-in, FCM push.
Amba for Android is published to Maven Central as com.layers.amba:amba-sdk-android. It supports every standard Android ABI and uses EncryptedSharedPreferences for credential storage.
Requirements: Android API 24+ (Android 7.0), Kotlin 1.9+, Java 17 toolchain.
1. Install via Gradle
Make sure mavenCentral() is in your project repositories:
Then add the dependency to your app module:
2. Configure in Application.onCreate
Register the Application class in AndroidManifest.xml:
Inject the API key via BuildConfig
Then add AMBA_API_KEY=amb_dev_ck_XXXX to your local.properties (gitignored). Replace with your real key from amba init or app.amba.dev.
3. First sign-in + first event
Amba.events.track is authenticated server-side — the request needs a session token. Sign in (anonymously is fine) before the first track call:
All Amba.* methods are suspend — call from a coroutine scope (lifecycleScope, viewModelScope, or your own CoroutineScope).
4. Session storage via EncryptedSharedPreferences
By default the SDK persists session tokens in EncryptedSharedPreferences (backed by the Android Keystore). No additional code is needed — the storage adapter is wired automatically when the androidx.security:security-crypto dependency is on the classpath.
Sessions survive app restarts, package upgrades, and reboots. They're cleared on full app reinstall (adb uninstall) or when the user explicitly signs out.
If you need a custom store (e.g. an in-memory store for tests, or a Room-backed adapter), construct AmbaClient directly:
5. Sign in with Google
Pull YOUR_GOOGLE_OAUTH_WEB_CLIENT_ID from Google's API credentials console — use the Web client ID, not the Android one.
6. Register for FCM push
Add Firebase to your project the standard way (google-services.json in app/, the Google Services Gradle plugin) and configure FCM in the amba console (server key + sender ID) once per package name.
7. First collection insert
The Kotlin SDK uses kotlinx.serialization for typed reads — findTyped<T>() decodes JSON straight into @Serializable data classes.
8. AI proxy
ProGuard / R8
The SDK ships with consumer rules in the published AAR — no app-side ProGuard config is required. Generated classes and runtime dependencies are kept automatically.
If you see UnsatisfiedLinkError: amba_core at runtime after enabling R8, verify the .so files actually shipped into your APK:
Should list one entry per ABI you've enabled in splits / abiFilters. If empty, the dependency wasn't bundled — check that implementation("com.layers.amba:amba-sdk-android:1.0.0") is in the runtime classpath, not compileOnly.
Common pitfalls
Amba.configurenot called beforeAmba.*throwsIllegalStateException("amba SDK not configured"). Always configure inApplication.onCreate, not in an Activity.- Calling SDK methods on the Main thread without a coroutine scope — every method is
suspend. UselifecycleScope.launch { ... }orviewModelScope.launch { ... }. - FCM token registered but no delivery — verify the Firebase Server Key in the amba console (Push → FCM) matches the project that issued the token. If you regenerated Firebase credentials, re-upload to amba.
- Google sign-in
DEVELOPER_ERROR(status code 10) — your debug keystore SHA-1 isn't registered on Google's OAuth client. Addkeytool -list -v -keystore ~/.android/debug.keystore | grep SHA1output to the Android OAuth client's authorized fingerprints. - App bundle size too large — by default the SDK includes all four ABIs (~7 MB raw). Use Android App Bundle (
bundleRelease) so Play Store delivers only the ABI matching each device. Don'tabiFiltersdown to a subset unless you know what you're doing — you'll lock out devices.
See also
- Client API reference — HTTP endpoint reference for every namespace.
- Code samples — same operations side-by-side with the other 7 SDKs.
- Push notifications — campaign API, scheduling, fan-out.
- SDK on Maven Central:
com.layers.amba:amba-sdk-android(search at search.maven.org).