Skip to content

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 ("[organisation]/[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#

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 properties = java.util.Properties()
        val localProperties = File(file)
        if (localProperties.isFile) {
            java.io.InputStreamReader(java.io.FileInputStream(localProperties), Charsets.UTF_8).use { reader ->
                properties.load(reader)
            }
        } 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#

To initialize LUNA ID in your project, specify the Application base class and the LunaID.init() function in the build.gradle.kts file:

class App : Application() {

    override fun onCreate() {
        super.onCreate()

        LunaID.init(
            app = this@App,
            lunaConfig = LunaConfig.create(),
            areDescriptorsEnabled = true
        )
    }
}

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.LunaCoreConfig
import ru.visionlabs.sdk.lunacore.LunaID  

class DemoApp : Application () {
    override fun onCreate() {
        super.onCreate()

        LunaID.init(
            app = this@App,
            lunaConfig = LunaConfig.create(),
            areDescriptorsEnabled = true
        )

        LunaID.showCamera() 

        LunaID.apiHuman

        // specify the URL to LUNA PLATFORM
        val baseUrl = "http://luna-platform.com/api/6/"
    }
}

The example has the following components:

Component Description
LunaID.init() Function. Initializes the LUNA ID library.
LunaID.showCamera() Method. Opens a mobile device camera.
LunaID.apiHuman Property. Provides access to the LUNA PLATFORM API and allows sending requests.
baseUrl Variable. Specifies the LUNA PLATFORM URL that is used by the LunaID.apiHuman() function.

For detailed examples, see: