Android Quickstart
This guide is for our new Kotlin Multiplatform SDK which is in Public beta. If you are instead looking for the stable version, please see stytch-android and the usage docs here.
consumer-headless or b2b-headless. Both SDKs are distributed via Maven Central and require Kotlin 2.3.0 or later.
1. Install the SDK
Make suremavenCentral() is in your repository configuration:
2. Initialize the Client
Create the client once — in yourApplication class or at the entry point of your auth flow. The client is a singleton; calling createStytchConsumer again returns the same instance.
createStytchConsumer with createStytchB2B and import from com.stytch.sdk.b2b.
Your public token is in the Stytch Dashboard. Make sure you’ve also enabled the auth methods you want to use under SDK Configuration.
3. Observe Authentication State
The SDK exposes aStateFlow that emits whenever the authentication state changes. Collect it from a ViewModel or lifecycleScope:
stytch.authenticationStateFlow.value.
4. Auth Methods
All SDK methods aresuspend functions. Call them from a coroutine scope and handle errors with try/catch. Errors are thrown as StytchError.
SMS OTP Example
5. Handle Deeplinks
Magic links and password reset emails redirect back to your app via a custom URL scheme. 1. Register a redirect URL in the Stytch Dashboard. Use a scheme likemyapp://auth.
2. Add an intent filter to your activity in AndroidManifest.xml:
6. Session Management
Sessions are automatically persisted across app launches and validated on startup.Callback Extensions
If your project uses callback-style APIs or calls the SDK from Java, swap the base artifact for the extensions variant — it re-exports the base SDK, so no other changes are needed:suspend method then gains an onSuccess/onFailure overload that returns a cancellable Job: