1️⃣ Getting started
In this short guide, you will learn how to integrate the Keyless Document SDK in your Android or iOS mobile application. You will learn how to read the document machine readable zone - MRZ - and how to scan the NFC tag of the document.
Prerequisites
Make sure you have both required API keys, and the list of productions hosts from your Keyless contact:
YOUR_CLOUDSMITH_TOKENto download the SDK from cloudsmith repositoryKEYLESS_API_KEYto configure the mobile SDKKEYLESS_HOSTSa list of node URLs. Urls inKEYLESS_HOSTSmust NOT contain any trailing slashes/.
Review the Keyless SDK requirements:
The Keyless SDK uses
Android 6.0 (API level 23) and above
The Keyless SDK uses
Set up a physical iOS device for running your app and enable the following permissions:
Enable Camera permissions: add the
Privacy - Camera Usage Descriptionkey in your project’sInfo.plistby adding the following (in XCode under Project > Info):<key>NSCameraUsageDescription</key> <string>Keyless needs access to your camera to enroll and authenticate you. Keyless cannot be used without your camera. Please allow camera permissions.</string>Enable background processing: necessary to synchronize Keyless data. You can find a comprehensive guide in the apple documentation. In a nutshell here is what you need to do: enable the
Background processingmode underSigning & Capabilities/Background Modes. Then, add the following in your project’sInfo.plit(in XCode, under the keyPermitted background task scheduler identifiers):<key>NSCameraUsageDescription</key> <key>BGTaskSchedulerPermittedIdentifiers</key> <array> <string>YOUR APP IDENTIFIER</string> </array>
The Keyless SDK uses
Flutter 3.0 or higher
Dart 3.0 or higher
All requirements from both Android and iOS platforms
Set up the required permissions as described in the Android and iOS tabs.
Installation
To allow Keyless to handle the result of registerForActivityResult, you must call Keyless from an Activity implementing ActivityResultCaller.
Extend any androidX activity that implements the interface for you, for example let your Activity extend the generic ComponentActivity or the more widespread AppCompatActivity.
If you use Proguard, add the following rules to your Proguard configuration file:
# Keyless Proguard -keep class io.keyless.documentsdk.** {*;} -keepclassmembers class io.keyless.documentsdk.** {*;}In the the
repositoriessection of thesettings.gradlefile of your Android application, add the following snippet, replacingYOUR_CLOUDSMITH_TOKENwith the CloudSmith token provided to you by Keyless.dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() maven { url "https://dl.cloudsmith.io/YOUR_CLOUDSMITH_TOKEN/keyless/partners/maven/" } } }In the
dependenciesblock of your projectbuild.gradlefile, typicallyapp/build.gradle, add:dependencies { // ... implementation 'io.keyless:keyless-document-sdk:+' }In the
androidblock of your projectbuild.gradlefile, typicallyapp/build.gradle, make sure you have the following options:android { // ... compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } // add the following only if you're using Kotlin kotlinOptions { jvmTarget = "1.8" } }
Create a Podfile if you don’t already have one
$ cd your-project-directory $ pod initSet up Cocoapods to use your Cloudsmith credentials, by running the following commands, replacing
YOUR_CLOUDSMITH_TOKENwith the Cloudsmith token provided you by Keyless.git config --global credential.helper store echo "https://token:[email protected]" >> ~/.git-credentialsAdd the KeylessSDK pod to your
Podfile# This is the Keyless repository for partners source 'https://dl.cloudsmith.io/basic/keyless/partners/cocoapods/index.git' target 'MyApp' do use_frameworks! # Add the Keyless pod pod 'KeylessDocumentSDK' endAdd the following at the bottom of you
Podfilepost_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['ENABLE_BITCODE'] = 'NO' end end endInstall the pods. If
podprompts you for authentication insert the stringtokenas your username and then fill inYOUR_CLOUDSMITH_TOKENas the password.$ pod install Analyzing dependencies Cloning spec repo `cloudsmith-basic-keyless-partners-cocoapods-index` from `https://dl.cloudsmith.io/basic/keyless/partners/cocoapods/index.git` Username for 'https://dl.cloudsmith.io': token Password for 'https://dl.cloudsmith.io': YOUR_CLOUDSMITH_TOKEN
Add the Keyless SDK repository
echo '${CLOUDSMITH_TOKEN}' | dart pub token add https://dart.cloudsmith.io/keyless/flutter/Add the Keyless SDK dependency to your
pubspec.yaml:dart pub add keyless_flutter_document_sdk:PACKAGE_VERSION --hosted-url https://dart.cloudsmith.io/keyless/flutter/Follow the installation steps in both the Android and iOS tabs to set up the native SDKs in their respective platforms.
Run flutter pub get to download the dependencies:
flutter pub get
You also need to bridge the native SDKs that are used by the flutter SDK. You can do that in the android and ios sections of your flutter project.
Android
Add the following line in the root build.gradle:
allprojects {
repositories {
google()
mavenCentral()
maven {
setUrl("https://dl.cloudsmith.io/YOUR_CLOUDSMITH_TOKEN/keyless/partners/maven/")
}
}
} Where YOUR_CLOUDSMITH_TOKEN should be replaced with the cloudsmith token provided by the Keyless integration support team.
Then, open your Android.manifest file and add the following lines inside the <application> tag.
<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
<meta-data
android:name="io.keyless.documentsdk.KeylessDocumentInitializer"
android:value="androidx.startup" />
<!-- ONLY if you also use the Keyless Mobile SDK -->
<meta-data
android:name="io.keyless.fluttersdk.KeylessInitializer"
android:value="androidx.startup" />
</provider>Make sure your settings.gradle (or settings.gradle.kts) includes Kotlin Android plugin version 1.9.0. This version is mandatory for compatibility across all modules.
Your plugin block should look like this:
pluginManagement {
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.7.0" apply false
id "org.jetbrains.kotlin.android" version "1.9.0" apply false // ✅ Required version
}
}In your app/build.gradle, make sure to exclude the following resource to prevent build conflicts caused by Java 9+ multi-release JARs:
android {
packaging {
resources {
excludes += "META-INF/versions/9/OSGI-INF/MANIFEST.MF"
}
}
}You must use NDK version 27.0.12077973:
android {
ndkVersion = "27.0.12077973"
}The minimum supported SDK version is 23:
defaultConfig {
minSdk = 23
}Example of app/build.gradle
android {
namespace = "namespace_id"
compileSdk = flutter.compileSdkVersion
ndkVersion = "27.0.12077973" // ✅ Required NDK version
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
defaultConfig {
applicationId = "application.id"
minSdk = 23 // ✅ Minimum supported SDK version
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}
packaging {
resources {
excludes += "META-INF/versions/9/OSGI-INF/MANIFEST.MF" // ✅ Prevents Java
}
}
}iOS
Make sure to target at least iOS 15 in your project.
Open your PodFile and add the following line:
source 'https://dl.cloudsmith.io/YOUR_CLOUDSMITH_TOKEN/keyless/partners/cocoapods/index.git'Where YOUR_CLOUDSMITH_TOKEN should be replaced with the cloudsmith token provided by the Keyless integration support team.
To enable NFC-based document scanning functionality in an iOS app, the following is required:
Enable the NFC Tag Reading Capability in Xcode:
Go to your target → Signing & Capabilities → click "+" → select Near Field Communication Tag Reading
Then, navigate to your Info.plist file, typically located in a folder called with your project name (e.g. Runner).
Add the following permissions declaration to this file (if not present already):
<key>NFCReaderUsageDescription</key>
<string>We need NFC access to read your document.</string>
<!-- Note: You can change the string value for NFCReaderUsageDescription according to your application -->
<key>NSCameraUsageDescription</key>
<string>This app uses the camera to scan the data</string>
<!-- Note: You can change the string value for NSCameraUsageDescription according to your application -->
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
<string>A0000002471001</string>
<string>A0000002472001</string>
<string>00000000000000</string>
</array>Initialization
There is some initialization to do before you can use the Keyless Document SDK.
Initialize the Keyless Document SDK in your
Applicationclass:// MainApplication override fun onCreate() { super.onCreate() // Initialize Keyless KeylessDocument.initialize(application = this) }Add your application to the Manifest
<application ... android:name=".MainApplication" ... </application>Configure the Keyless Document SDK:
// MainActivity override fun onCreate() { super.onCreate() KeylessDocument.configure( KeylessDocument.Config( apiKey = KEYLESS_API_KEY, hostURl = KEYLESS_HOST, ), ) }
Create an instance object of
KeylessDocumentinitializing it with the api key and host you received from your Keyless contact.KeylessDocument.configure( configuration: .init( host: KEYLESS_HOST, apiKey: KEYLESS_API_KEY ) )
Import the required packages:
import 'package:keyless_flutter_document_sdk/keyless_document.dart';Configure the Keyless SDK in your app's initialization code:
final keylessDocumentConfig = KeylessDocumentConfig( apiKey: KEYLESS_API_KEY, host: KEYLESS_HOST, ); try { await KeylessDocument.instance.configure(keylessDocumentConfig); print("Keyless Document SDK configured successfully"); } catch (error) { print("Failed to configure Keyless Document SDK: $error"); }🎨 Optional: UI Customization
The SDK allows customization of the UI to better match your app’s branding or UX requirements. You can define colors and override default texts for various UI components.
Example:
final keylessDocumentConfig = KeylessDocumentConfig( apiKey: KEYLESS_API_KEY, host: KEYLESS_HOST, logsConfiguration: LogsConfiguration( enabled: true, logLevel: document_sdk.LogLevel.debug, ), uiCustomization: UICustomization( primaryColor: 0xFF0B3EE3, rangeFinderOverlayColor: 0xFFFFD966, documentDetailsTitle: "Enter Document Details", documentNumberFieldHint: "e.g., 123456789", confirmButtonText: "Continue", nfcInfoText: "Hold your phone near the document" ), );UICustomization supports the following fields:
CategoryParameterDescriptionColors
primaryColorA primary shown most frequently across screens and components
onPrimaryColorColor shown on top of the primary color
accentColorAccent color
rangeFinderOverlayColorMRZ Rectangle color during document scanning
MRZ / Manual
mrzGoToManualInputButtonText for switching to manual input
Input
documentDetailsTitleTitle on manual input screen
documentNumberFieldTitleLabel for document number field
documentNumberFieldHintPlaceholder/hint for document number
birthDayFieldTitleLabel for date of birth field
expiryDateFieldTitleLabel for expiry date field
cancelButtonTextText for cancel button
confirmButtonTextText for confirm/continue button
Android only
documentNumberFieldErrorMessageError message if document number is invalid (Android)
birthDayFieldErrorMessageError message for birthday field (Android)
expiryDateFieldErrorMessageError message for expiry date (Android)
NFC
nfcInfoTextInstruction text shown before starting NFC scan
iOS only
nfcConnectionLostText shown when NFC connection is lost (iOS only)
Theme
sdkThemeTheme to use (
light,dark, or system default)💡 All fields are optional. If not set, the SDK will fall back to default values.
Make sure to set up the required permissions in both Android and iOS platforms as described in their respective tabs.
Last updated
Was this helpful?