Initial setup of LUNA ID for Android#
This topic describes how to perform the initial setup of LUNA ID to start using it in your Android projects.
Step 1. Get the .aar file#
To download the .aar file:
1․ Specify the file repository.
2․ Provide user credentials in the local.properties file.
3․ Add the following code fragment to the repositories
block in the settings.gradle.kts file:
The settings.gradle.kts file is located in the root directory of your project and defines which projects and libraries you need to add to your build script classpath.
repositories {
...
ivy {
url = java.net.URI.create("https://download.visionlabs.ru/")
patternLayout {
artifact ("releases/lunaid-[artifact]-[revision].[ext]")
setM2compatible(false)
}
credentials {
username = getLocalProperty("vl.login") as String
password = getLocalProperty("vl.pass") as String
}
metadataSources { artifact() }
}
}
Step 2. Provide your user credentials#
Important: Only authorized users can download artifacts from https://download.visionlabs.ru/.
To provide your user credentials, in the local.properties file:
1․ Specify your user credentials:
vl.login=YOUR_LOGIN
vl.pass=YOUR_PASSWORD
2․ Add a function for getting your login and password:
fun getLocalProperty(key: String, file: String = "local.properties"): Any {
val file = File(rootProject.projectDir, file)
val properties = java.util.Properties()
val localProperties = file
if (localProperties.isFile) {
java.io.InputStreamReader(java.io.FileInputStream(localProperties), Charsets.UTF_8)
.use { reader ->
properties.load(reader)
}
} else if (System.getenv("CI") != null) {
// on CI we dont really use it
return "nothing"
} else error("File from not found: '$file'")
if (!properties.containsKey(key)) {
error("Key not found '$key' in file '$file'")
}
return properties.getProperty(key)
}
We recommend that you add the local.properties file to .gitignore for the version control system does not track the file.
Step 3. Add the .aar file as a dependency#
To initialize LUNA ID with your project, you need to add the .aar file as a dependency in the build.gradle.kts file. The build.gradle.kts file defines various build settings such as dependencies, plugins, library versions, compilation and testing settings, and so on. All these settings affect how the project is build and what functionality it contains.
To add the .aar file as a dependency, add the following piece of code to the dependencies
block of the build.gradle.kts file:
dependencies {
...
implementation("ai.visionlabs.lunaid:core:{VERSION}@aar")
}
For example, implementation("ai.visionlabs.lunaid:core:1.2.3@aar")
.
You need to update the
{VERSION}
parameter when a new version of LUNA ID is released.
Step 4. Initialize LUNA ID and activate the license#
To initialize LUNA ID in your project and activate the license as shown in the example below:
Note: The parameters in the example are set to default values.
import android.app.Application
import ru.visionlabs.sdk.lunacore.LunaConfig
import ru.visionlabs.sdk.lunacore.LunaID
import ru.visionlabs.sdk.lunacore.liveness.GlassesCheckType
import ru.visionlabs.sdk.lunaweb.v6.ApiHumanConfig
class DemoApp : Application() {
override fun onCreate() {
super.onCreate()
val baseUrl = "url"
val token = "token"
val headers = mapOf("Authorization" to token)
val apiHumanConfig = ApiHumanConfig(baseUrl, headers)
val lunaConfig = LunaConfig.create(
acceptOccludedFaces = true,
acceptOneEyed = false,
acceptEyesClosed = false,
detectFrameSize = 350,
skipFrames = 36,
ags = 0.5f,
bestShotInterval = 500,
detectorStep = 1,
usePrimaryFaceTracking = true,
glassesChecks = setOf(GlassesCheckType.GLASSES_CHECK_SUN)
)
LunaID.activateLicense(
app = this,
lunaConfig = lunaConfig,
apiHumanConfig = apiHumanConfig
)
}
}
Important: For complete instructions on how to activate the LUNA ID license, see Licensing.
The example has the following components:
Component | Description |
---|---|
baseUrl |
A variable that specifies the URL to LUNA PLATFORM 5. For details, see Interaction of LUNA ID with LUNA PLATFORM 5. |
token |
A variable that specifies a LUNA PLATFORM 5 token, which will be transferred to a request header from LUNA ID. |
headers |
A map that specifies headers that will be added to each request to be sent to LUNA PLATFORM 5. |
apiHumanConfig |
An optional configuration parameter for calling the LUNA PLATFORM 5 API. Can be set to null if no LUNA PLATFORM 5 API calls are required. This will also disable the Online OneShotLiveness estimation, regardless of the onlineLivenessSettings argument. |
ApiHumanConfig |
A class required for configuration to call the LUNA PLATFORM 5 API. |
lunaConfig |
An argument to be passed for best shot parameters. |
LunaConfig |
A class that describes best shot parameters. |
acceptOccludedFaces |
A parameter that specifies whether an image with an occluded face will be considered the best shot. For details, see Getting the best shot with an occluded face. |
acceptOneEyed |
A parameter that specifies whether blinking with one eye is enabled. |
acceptEyesClosed |
A parameter that specifies whether an image with two closed eyes will be considered the best shot. For details, see Getting the best shot with faces with closed eyes. |
detectFrameSize |
A parameter that specifies a face detection bounding box size. |
skipFrames |
A parameter that specifies a number of frames to wait until a face is detected in the face recognition area before video recording is stopped. |
ags |
A parameter that specifies a source image score for further descriptor extraction and matching. For details, see AGS. |
bestShotInterval |
A parameter that specifies a minimum time interval between best shots. |
detectorStep |
A parameter that specifies a number of frames between frames with full face detection. |
usePrimaryFaceTracking |
Specifies whether to track the face that was detected in the face recognition area first. For details, see Tracking face identity. |
glassesChecks |
Specifies what images with glasses can be best shots. For details, see Getting the best shot with faces with occluded eyes. |
LunaID.activateLicense |
A method that activates the LUNA ID license. |
Step 5. Call LUNA ID functions#
To use LUNA ID functionality, such as open a camera, send a request to LUNA PLATFORM 5, and so on, import LUNA ID libraries and specify the required functions in the build.gradle.kts file. Consider the following example:
import android.app.Application
import ru.visionlabs.sdk.lunacore.LunaConfig
import ru.visionlabs.sdk.lunacore.LunaID
import ru.visionlabs.sdk.lunaweb.v6.ApiHumanConfig
class DemoApp : Application () {
override fun onCreate() {
super.onCreate()
val token = "token"
val headers = mapOf("Authorization" to token)
LunaID.activateLicense(
app = this,
lunaConfig = LunaConfig.create(),
apiHumanConfig = ApiHumanConfig("url", headers)
)
}
}
...
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import ru.visionlabs.lunademo.R
import ru.visionlabs.sdk.lunacore.LunaID
class MainActivity : AppCompatActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
LunaID.showCamera(this)
}
}
For detailed examples, see: