Skip to content

Building the Android Age Verification App.

This guide aims to assist developers build and test the Android Age Verification application.

Table of contents

Prerequisites

  • Java Development Kit (JDK): JDK 8 or higher is required to compile Java or Kotlin code for Android
  • Android Studio: The official IDE for Android development, which includes essential tools like the Android SDK, build tools, and an emulator
  • Android SDK Tools: These provide libraries, debuggers, and other utilities needed for building Android apps
  • Gradle: The build automation system used to compile, package, and manage dependencies for your app

Building the app

Clone the Android repository from GitHub to your local machine and open the project in Android Studio.

The application has two product flavors: - "Dev", which communicates with the services deployed in an environment based on the latest main branch. - "Demo", which communicates with the services deployed in an environment based on the latest main branch.

and two Build Types: - "Debug", which has full logging enabled. - "Release", which has no logging enabled.

which, ultimately, result in the following Build Variants:

  • "devDebug", "devRelease", "demoDebug", "demoRelease" .

To change the Build Variant, go to Build -> Select Build Variant and from the tool window you can click on the "Active Build Variant" of the module ":app" and select the one you prefer. It will automatically apply it for the other modules as well.

To run the App on a device, firstly you must connect your device with the Android Studio, and then go to Run -> Run 'app'. To run the App on an emulator, simply go to Run -> Run 'app'.

Running with remote services

If you wish to test the application with the Issuer and Verifier services provided by the Toolbox, you can utilize the online services that are publicly available. The configuration below is already predefined within the app for this purpose.

The Configuration is defined in two ConfigWalletCoreImpl.kt files (located in the "core-logic" module, in either src\dev\java\eu\europa\ec\corelogic\config or src\demo\java\eu\europa\ec\corelogic\config, depending on the flavor of your choice).

These are the contents of the ConfigWalletCoreImpl file (dev flavor) and you don't need to change anything:

private companion object {
        const val VCI_ISSUER_URL = "https://issuer.ageverification.dev/"
        const val VCI_CLIENT_ID = "wallet-dev"
        const val AUTHENTICATION_REQUIRED = false
}

Running with local services

If you prefer not to use the online services and instead wish to run or operate them locally, you will need to install three software components. In the following, we will focus on the scenario where the services are started locally.

For detailed instructions on how to set up each of these components, please refer to the documentation provided for each respective component. * Issuer * Web Verifier UI * Web Verifier Endpoint

After this, and assuming you are now running everything locally, you need to change the contents of the ConfigWalletCoreImpl file, from:

private companion object {
        const val VCI_ISSUER_URL = "https://issuer.ageverification.dev/"
        const val VCI_CLIENT_ID = "wallet-dev"
        const val AUTHENTICATION_REQUIRED = false
}
into something like this:
private companion object {
        const val VCI_ISSUER_URL = "local_IP_address_of_issuer"
        const val VCI_CLIENT_ID = "wallet-dev"
        const val AUTHENTICATION_REQUIRED = false
}

for example:

private companion object {
        const val VCI_ISSUER_URL = "https://192.168.1.1:5000"
        const val VCI_CLIENT_ID = "wallet-dev"
        const val AUTHENTICATION_REQUIRED = false
}

Finally, you have to also change the content of network_security_config.xml file and allow HTTP traffic, to this:

<network-security-config>
    <base-config cleartextTrafficPermitted="true" />
</network-security-config>

How to work with self-signed certificates

This section describes configuring the application to interact with services utilizing self-signed certificates.

  1. Open the build.gradle.kts file of the "core-logic" module.
  2. In the 'dependencies' block add the following two:
    implementation(libs.ktor.android)
    implementation(libs.ktor.logging)
    
  3. Now, you need to create a new kotlin file ProvideKtorHttpClient and place it into the src\main\java\eu\europa\ec\corelogic\config package.
  4. Copy and paste the following into your newly created ProvideKtorHttpClient kotlin file.
    import android.annotation.SuppressLint
    import io.ktor.client.HttpClient
    import io.ktor.client.engine.android.Android
    import io.ktor.client.plugins.logging.Logging
    import java.security.SecureRandom
    import javax.net.ssl.HostnameVerifier
    import javax.net.ssl.SSLContext
    import javax.net.ssl.TrustManager
    import javax.net.ssl.X509TrustManager
    import javax.security.cert.CertificateException
    
    object ProvideKtorHttpClient {
    
        @SuppressLint("TrustAllX509TrustManager", "CustomX509TrustManager")
        fun client(): HttpClient {
            val trustAllCerts = arrayOf<TrustManager>(
                object : X509TrustManager {
                    @Throws(CertificateException::class)
                    override fun checkClientTrusted(
                        chain: Array<java.security.cert.X509Certificate>,
                        authType: String
                    ) {
                    }
    
                    @Throws(CertificateException::class)
                    override fun checkServerTrusted(
                        chain: Array<java.security.cert.X509Certificate>,
                        authType: String
                    ) {
                    }
    
                    override fun getAcceptedIssuers(): Array<java.security.cert.X509Certificate> {
                        return arrayOf()
                    }
                }
            )
    
            return HttpClient(Android) {
                install(Logging)
                engine {
                    requestConfig
                    sslManager = { httpsURLConnection ->
                        httpsURLConnection.sslSocketFactory = SSLContext.getInstance("TLS").apply {
                            init(null, trustAllCerts, SecureRandom())
                        }.socketFactory
                        httpsURLConnection.hostnameVerifier = HostnameVerifier { _, _ -> true }
                    }
                }
            }
        }
    
    }
    
  5. Finally, add this custom HttpClient to the EudiWallet provider function provideEudiWallet located in LogicCoreModule.kt
    @Single
    fun provideEudiWallet(
    context: Context,
    walletCoreConfig: WalletCoreConfig,
    walletCoreLogController: WalletCoreLogController
    ): EudiWallet = EudiWallet(context, walletCoreConfig.config) {
        withLogger(walletCoreLogController)
        // Custom HttpClient
        withKtorHttpClientFactory {
            ProvideKtorHttpClient.client()
        }
    }
    

For all configuration options please refer to this document