Skip to main content
com.trevosdk:trevosdk-android runs experiments and records events in Android apps, assigning the same variant the web SDK does for the same user. Kotlin, no dependencies beyond the Kotlin standard library, Android 5.0 (API 21) and later. Kotlin projects need Kotlin 2.0 or later; Java projects work as they are.
The library declares the INTERNET permission, which merges into your manifest.

Create the client

Use a Mobile key (tsk_live_…). Keep it in your build configuration, for example a buildConfigField, and create one client in Application.onCreate:
The client reads the build’s versionName, so minAppVersion gating and the version on every event work with no setup. Every method is safe to call from any thread. Create it in the main process only: a second process would share its files.

Read a variant

getVariant is synchronous and safe on the main thread. It returns control until stored state and the first config fetch have loaded, so wait for ready() (a suspend function) or whenReady { } before showing experiment UI:
Each call records an exposure the first time. Pass trackExposure = false to read without recording one. onChange calls a listener on the main thread whenever config or identity changes; keep the returned TrevoSubscription and cancel() it when the screen goes away.

Parameters

A parameter lets later experiments change a value with no release:
There are overloads for String, Boolean, Int, Long and Double. A value of another type, or a number that isn’t whole for Int or Long, serves the default. A String parameter can carry text per language: pass your app’s own translation as the default, and if users can pick the app’s language, call trevo.setLocale("pt-BR") when they do. Without it the SDK reads the app’s configured locale.

Track events and identify users

Property values are strings, numbers, booleans, lists, maps or null. Events are queued on disk and sent in batches every 15 seconds, when the app moves to the background, and on flush(). See Mobile experiments for how experiments ramp on mobile, how the SDK survives a lost network, and the Google Play data safety answers.

Options

Correctness

The library runs the shared conformance vectors in CI, so a change that would assign a user differently from the web fails the build. The rules are in the bucketing spec.