Getting started
Prerequisites
Before you can get started, you must first install the following software:
- Android studio from the Android developer documentation.
- Java Development Kit 17 (JDK) from the Oracle website.
Recommended Kotlin version
The SDK is made using Kotlin 2.1. If your app uses Kotlin, then we recommend that you use a language version that is the same (2.1) or newer.
The Kotlin binary format is often forwards compatible with the next Kotlin language release, but not later ones. Although this means that the minimum supported Kotlin language version is generally one version prior (2.0), we cannot guarantee compatibility.
Minimum Android version
The minimum supported Android version for the Encap SDK is Android 9.0 (API level 28).
Add the SDK to your application
The Encap SDK is available from our repository. The repository is gated, therefore you require login credentials to access it.
You need to add the Encap client API to the application using Android studio and Gradle. To do this:
- Request your Nexus repository login credentials from us by creating a support ticket in the Signicat Dashboard.
- Once you have obtained access, you can set your Nexus repository login credentials:
- Navigate to
$HOME/.gradle/gradle.properties. - Set the following credentials:
Example: Set your Nexus repository login credentials
mavenUser=<YOUR_NEXUS_REPOSITORY_USER_ID>
mavenPassword=<YOUR_NEXUS_REPOSITORY_PASSWORD>
- Navigate to
- Add Encap as dependency in your app's
build.gradlefile:
- Gradle (Kotlin)
- Gradle (Groovy)
dependencies {
implementation("com.encapsecurity:encap-android-api:3.20.3@aar")
}
dependencies {
implementation "com.encapsecurity:encap-android-api:3.20.3@aar"
}
- Add Encap as a custom repository in your project's
build.gradlefile.- For Encap SCA customers:
- Gradle (Kotlin)
- Gradle (Groovy)
Example: Add Encap as a custom repositoryallprojects {
repositories {
maven {
credentials {
username = providers.gradleProperty("mavenUser").get()
password = providers.gradleProperty("mavenPassword").get()
}
url = uri("https://nexus.pub.encap.no/content/repositories/encap-partner-repository")
}
}
}Example: Add Encap as a custom repositoryallprojects {
repositories {
maven {
credentials {
username mavenUser
password mavenPassword
}
url "https://nexus.pub.encap.no/content/repositories/encap-partner-repository"
}
}
}- For MobileID customers:
- Gradle (Kotlin)
- Gradle (Groovy)
Example: Add Encap as a custom repositoryallprojects {
repositories {
maven {
credentials {
username = providers.gradleProperty("mavenUser").get()
password = providers.gradleProperty("mavenPassword").get()
}
url = uri("https://nexus.pub.encap.no/content/repositories/MobileID-partner")
}
}
}Example: Add Encap as a custom repositoryallprojects {
repositories {
maven {
credentials {
username mavenUser
password mavenPassword
}
url "https://nexus.pub.encap.no/content/repositories/MobileID-partner"
}
}
}
Load the library
Before you can use the library, it needs to be loaded. You need to do this in a way where the library is only loaded once.
For example, you could implement this using the following code:
- Kotlin
- Java
class MyApp : Application() {
companion object {
init {
System.loadLibrary("encap-android-native-api")
}
}
}
public class MyApp extends Application {
static {
System.loadLibrary("encap-android-native-api");
}
}
Create a controller
The main interface of the Encap client API is the Controller. Many of the operations that you can execute with the controller are comprised of a start and finish call. For example startActivation() and finishActivation().
You can obtain the Encap controller instance using AndroidControllerFactory or AndroidLoggingControllerFactory, which are based on a singleton pattern. There can only be one instance of a specific controller with a certain name.
The first call will always create a controller. Any other calls after that will return the previously created instance.
The Controller can be created using AndroidControllerFactory:
- Kotlin
- Java
val controller = if (DEBUG) {
AndroidLoggingControllerFactory.getInstance(baseContext, "BankOne")
} else {
AndroidControllerFactory.getInstance(baseContext, "BankOne")
}
EncapController controller;
if (DEBUG) {
controller = AndroidLoggingControllerFactory.getInstance(getBaseContext(), "BankOne");
} else {
controller = AndroidControllerFactory.getInstance(getBaseContext(), "BankOne");
}
The log produced by AndroidLoggingControllerFactory in the code example above is available using standard Android tools.
For example, you could use the logcat tool, with tag Encap and a message level of INFO.
For production, you should use the no-logging factory AndroidControllerFactory and optimise/obfuscate the application so that unused classes are removed.
Controllers do not share any information between themselves, so it is not possible to perform registration migrations.
A created registration will only be available on the specified controller which is identified by a name.
Configure the controller
To configure the controller, you need to create a new instance of EncapConfig, and set that on the controller.
There are three properties that you always need to set, whereas the other properties are optional.
- Kotlin
- Java
controller.config = EncapConfig(
serverUrl = "https://serverurl.com", // Required
applicationId = "MyApplicationId", // Required
publicKeyBase64 = E2EE_KEY, // Required
connectionTimeout = 20000,
isClientOnly = false,
publicKeyHashes = hash,
pushToken = token,
allowDebugData = true,
locationEnabled = true,
)
controller.setConfig(new EncapConfig.Builder()
.setServerUrl("https://serverurl.com") // Required
.setApplicationId("MyApplicationId") // Required
.setPublicKeyBase64(E2EE_KEY) // Required
.setConnectionTimeout(20000)
.setClientOnly(false)
.setPublicKeyHashes(hash)
.setPushToken(token)
.setAllowDebugData(true)
.setLocationEnabled(true)
.build());
For MobileID customers, you must configure the following properties in the controller. This applies to both sandbox and production accounts: