Skip to content

Android Quickstart

Requirements

The Privy Android SDK requires Android API 27 (Android 8.1 Oreo) or higher and is built with with Kotlin 2.1.0.

Installation

The Privy Android SDK is available on Maven Central.

  1. Inclue the mavenCentral() repository in your gradle files.
kotlin
repositories { 
    google()
    mavenCentral() 
} 
  1. Add the latest Privy SDK dependency, where X.Y.Z is the latest version, which can be found here.
kotlin
dependencies { 
  // other deps
  implementation(libs.androidx.compose.material3)
  implementation(libs.androidx.compose.ui.tooling.preview)

  // Privy Core
  implementation("io.privy:privy-core:X.Y.Z") 
} 

TIP

Before integrating, you must register your allowed application IDs in the Privy Developer Dashboard, under App Settings > Clients.

Initialization

Initialize a Privy instance with your application context and a PrivyConfig object.

The configuration fields are:

FieldTypeRequired?Description
appIdStringYesYour Privy application ID, which can be obtained from the Privy Developer Dashboard, under App Settings > Basics
appClientIdStringYesYour app client ID, which can be obtained from the Privy Developer Dashboard, under App Settings > Clients
logLevelPrivyLogLevel?No(Optional) Your preferred log level. If no log level is specified, it will default to PrivyLogLevel.NONE.
customAuthConfigLoginWithCustomAuthConfig?No(Optional) Only use this if you plan to use custom authentication. Find more information here.
kotlin
private val privy: Privy =
   Privy.init(
       context = applicationContext, // be sure to only pass in Application context
       config = PrivyConfig(
           appId = "YOUR_APP_ID",
           appClientId = "YOUR_APP_CLIENT_ID",
           logLevel = PrivyLogLevel.VERBOSE
       )
   )

TIP

Be sure to maintain a single instance of Privy across the lifetime of your application. Initializing multiple instances of Privy will result in unexpected errors.

Await Ready

When the Privy SDK is initialized, the user's authentication state will be set to NotReady until Privy finishes initialization. During this time, we suggest you show a loading state to your user. For you convenience, we've added a suspending awaitReady() function. Here's an example with some pseudocode:

kotlin
// Launch a coroutine in order to await Privy's ready state
viewModelScope.launch {
  // Show loading UI
  uiState = .loading

  // Await ready
  privy.awaitReady()

  // Check if user is authenticated
  val isPrivyUserAuthenticated = privy.authState.value.isAuthenticated()

  // Show loaded UI accordingly
  uiState = .loaded(isPrivyUserAuthenticated)
}

INFO

Call awaitReady() to suspend execution until Privy is ready.

That's it! You can now use the Privy SDK to securely authenticate and provision embedded wallets for your users. 🎉