The simplest way to initialize Malwarelytics for Android is in the Application.onCreate() system callback. A bare minimum required for integration is to provide apiUsername, apiPassword and apiSignaturePublicKey to the AppProtectionConfig.Builder. Additionally, in order for RASP features to be enabled with default configuration, application signatureHash must be supplied.

Here is an example of minimum initialization code including RASP features:

class MyApplication : Application() {

    override fun onCreate() {
        // Prepare minimum configuration
        val config = AppProtectionConfig.Builder(appContext)
            .clientAppUserId(INTERNAL_CLIENT_USER_ID) // Use if internal user ID is available at config time
            .clientAppDeviceId(INTERNAL_CLIENT_DEVICE_ID) // Use if internal device ID is available at config time

        // Initialize AppProtection class
        val appProtection = AppProtection.getInstance()
        appProtection.initializeAsync(config, object: AppProtection.InitializationObserver {
            // App Protection is fully ready to be used now
            override fun onInitialized(initializationResult: InitializationResult) {
                // Setup internal IDs when you are able to obtain them
        // ...

The API_USERNAME, API_PASSWORD and API_SIGNATURE_PUBLIC_KEY values can be found in the Malwarelytics console.

INTERNAL_CLIENT_USER_ID and/or INTERNAL_CLIENT_DEVICE_ID are your custom identifiers that allow you to recognize your client.

For information on how to obtain the SIGNATURE_HASH value, read the Repackaging Detection guide.

See the RASP feature overview and the Anti-Malware feature overview for detailed documentation of available detections and security features.

Configuration Reference List

This is a reference list of all configuration options.


Global Malwarelytics configuration options:

val config = AppProtectionConfig.Builder(appContext)

    // Anti-Malware feature configuration

    // RASP feature configuration

    // API username

    // API password

    // API signature public key

    // change environment configuration

    // custom identifier of client

    // custom identifier of client device

    // configuration of customer grouping and naming in the web app



Configuration options for the Anti-Malware component:

val antivirusConfig = AntivirusConfig.Builder()
                // define if the Anti-Malware component of Malwarelytics is enabled

                // use default built-in suggestions

                // set factory for foreground service notification

                // set detailed configuration of smart protection

                // change default threat mitigation UI - screen & notification



Configuration options for Threat Mitigation UI, an Anti-Malware feature:

val threatMitigationUIConfig = AntivirusConfig.ThreatMitigationUIConfig.Builder()


Configuration options for Smart Protection, an Anti-Malware feature:

val smartProtectionConfig = AntivirusConfig.SmartProtectionConfig.Builder()


Configuration options for the RASP component:

val raspConfig = RaspConfig.Builder()
    .exitOnRootMinConfidence(Float) // value from 0.0 to 1.0
    .signatureHash(String)          // SHA-1 of signing certificate(s)
    .customProcessName(String)      // when set, turns of useStealthyProcessName


Configuration options for customer grouping in the web console:

val customerGroupingConfig = AppProtectionConfig.CustomerGroupingConfig.Builder()
    .sourcePackageName(String) // max len 255 characters
    .appPackageName(String) // max len 255 characters
    .audienceGroupId(String) // max len 20 characters

Configuration of Server Environment

Malwarelytics provides two predefined environments — production and test. The production environment is used by default. Environment can be specified with these pre-defined constants:

// Production environment
val environmentConfiguration = AppProtectionConfig.EnvironmentConfiguration.PRODUCTION_ENVIRONMENT

// Test environment
val environmentConfiguration = AppProtectionConfig.EnvironmentConfiguration.TEST_ENVIRONMENT

Environment configuration can be set only through configuration of AppProtection.

val config = AppProtectionConfig.Builder(appContext)
    // …

For special use, environment configuration allows definition of custom environments with optional SSL pinning. These custom environments can be defined with:

// The argument defines environment URL. No SSL pinning is used in this case.
val environmentConfiguration = EnvironmentConfiguration(String)

// The first argument defines environment URL.
// The second argument is supposed to contain values of SHA-256 digests of certificate data - X509Certificate.encoded.
val environmentConfiguration = EnvironmentConfiguration(String, List<ByteArray>)

// The first argument defines environment URL.
// The second argument is supposed to contain base64 encoded values of SHA-256 digests of certificate data - X509Certificate.encoded.
val environmentConfiguration = EnvironmentConfiguration(String, vararg String)

Configuration Change

Any configuration change of Malwarelytics for Android requires releasing AppProtection instance and re-initializing with a new configuration.

More details about releasing AppProtection instance are described in Releasing section of the documentation.

Malwarelytics for Android cannot be used after release. It has to be re-initialized first.

Last updated on May 18, 2023 (13:42) View product


Malwarelytics for Android