Biometry authentication (Touch ID, Face ID, fingerprint) for Android and iOS from shared Kotlin Multiplatform code.
- Check availability —
BiometryAuthenticator.isBiometryAvailable()returnsBiometryAvailability(supported type, error message). - Authenticate —
BiometryAuthenticator.authenticate()shows the system dialog and returnsBiometryResult(Success / Cancelled / Error). - Shared models —
BiometryResult,BiometryAvailability,BiometryTypeincommonMain. - Android —
BiometricManager+BiometricPrompt(runs on main thread). - iOS —
LocalAuthenticationframework (Touch ID / Face ID).
| Gradle | 8.0+ |
| Kotlin | 2.0+ |
| Android | minSdk 23+, compileSdk 34 |
| iOS | 11.0+ |
Repositories (root settings.gradle.kts or build.gradle.kts):
repositories {
mavenCentral()
google()
}Dependency (your KMP module):
// commonMain
commonMain.dependencies {
implementation("dev.enumset:biometry-auth:1.0.0")
}Use from a coroutine (recommended: Dispatchers.Main on Android for UI):
val authenticator = createBiometryAuthenticator()
// Check availability
val availability = authenticator.isBiometryAvailable()
if (!availability.isAvailable) {
// availability.errorMessage, availability.biometryType
return
}
// Authenticate
when (val result = authenticator.authenticate(
title = "Sign in",
subtitle = "Confirm your identity",
negativeButtonText = "Cancel",
allowDeviceCredentials = true
)) {
is BiometryResult.Success -> { /* success */ }
is BiometryResult.Cancelled -> { /* user cancelled */ }
is BiometryResult.Error -> { /* result.message, result.code */ }
}- Before using biometry, set the
FragmentActivity(e.g. inonCreate):
import dev.enumset.biometry.setFragmentActivityForBiometry
// In your FragmentActivity
setFragmentActivityForBiometry(this)- Call from a coroutine with
Dispatchers.Main(dialog must run on main thread):
lifecycleScope.launch(Dispatchers.Main) {
val authenticator = createBiometryAuthenticator()
val result = authenticator.authenticate(
title = "Sign in",
subtitle = "Confirm your identity",
negativeButtonText = "Cancel",
allowDeviceCredentials = true
)
}Use the same common API: createBiometryAuthenticator() and authenticate(). The actual implementation uses LocalAuthentication.
Add to your app Info.plist (required for Face ID):
<key>NSFaceIDUsageDescription</key>
<string>Authenticate with Face ID or Touch ID</string>| Module | Description |
|---|---|
sample/androidApp |
Android app (availability check + auth). |
sample/composeApp |
Compose Multiplatform sample (Android + iOS). |
sample/iosApp |
Native iOS app + Xcode integration. |
Run Android sample:
./gradlew :sample:androidApp:assembleDebug
./gradlew :sample:androidApp:installDebugiOS: build the framework with ./gradlew :biometry:linkDebugFrameworkIosSimulatorArm64 and follow sample/iosApp/README.md for Xcode.
The library does not declare permissions. Your app must add them.
Android — in your app manifest:
USE_BIOMETRIC(API 28+)USE_FINGERPRINT(API 23–27, deprecated in 28)
See Biometric authentication | Android Developers.
./gradlew :biometry:build