Android support

Since v7.38.0, LicenseSpring provides a C++ SDK built using the Android NDK, designed for Android applications. The SDK is compatible with Android devices running Android API Level 24 (Android 7.0 Nougat) or higher.

  • NDK Version: 26.1.10909125 and 27.2.12479018

  • Minimum Android API Level: 24 (Android 7.0 Nougat)

  • ABI version: arm64-v8

The SDK provides native C++ functionality and is optimized for performance on supported Android devices.

JNI initialization

The SDK includes JNI code used for computing the hardware ID of the Android device, and the default data path used for writing the license and log files:

  • Secure.getString(getApplicationContext().getContentResolver(), Secure.ANDROID_ID) is used to compute the hardware ID.

  • context.getFilesDir().getAbsolutePath() is used to compute the default data path.

To set these values and integrate the native LicenseSpring library into your app, include the following class in your project.

LicenseSpring.kt
package com.licensespring.android

import android.content.Context
import android.util.Log

object LicenseSpring {

    // This method decalaration exactly matches the signature declared in the LicenseSpring SDK. Don't remove it.
    external fun setAndroidContextAndIDs(context: Context)

    init {
        try {
            System.loadLibrary("LicenseSpring")
            Log.d("LicenseSpring", "Native library loaded successfully")
        } catch (e: UnsatisfiedLinkError) {
            Log.e("LicenseSpring", "Failed to load native library: ${e.message}")
        }
    }

    fun initialize(appContext: Context) {
        try {
            setAndroidContextAndIDs(appContext.applicationContext)
            Log.d("LicenseSpring", "Native context and IDs set successfully")
        } catch (e: Exception) {
            Log.e("LicenseSpring", "Error calling native method: ${e.message}")
        }
    }
}
circle-info

Include this snippet in your project and call LicenseSpring.initialize(context) during your app startup. If you don't want to pass the context to the LicenseSpring C++ SDK, you must set your own hardware IDarrow-up-right and data path.arrow-up-right

A full example is contained in the samples/AndroidNDKSample project, together with a demo Android app where you can activate and check licenses.

Was this helpful?