Skip to main content

Installation

KapePlatformSDK is hosted on a private Cloudsmith maven registry. Downloading from Cloudsmith requires a entitlement token, reach your contact at Kape if you have not received an entitlement token.

Gradle (Kotlin DSL)​

Add the Kape Maven repository and dependency to your build files:

// settings.gradle.kts
dependencyResolutionManagement {
repositories {
maven {
url = uri("https://dl.cloudsmith.io/basic/expressvpn/kp_platform_sdks/maven/")
credentials {
username = "token"
password = "<YOUR_ENTITLEMENT_TOKEN>"
}
}
}
}
// app/build.gradle.kts
dependencies {
implementation("com.kape.platformsdk:kape-platform-sdk:<version>")
// One per VPN protocol the app supports — pass the matching object to KapeVpnManager
implementation("com.kape.platformsdk:kape-platform-sdk-wireguard:<version>")
implementation("com.kape.platformsdk:kape-platform-sdk-lightway:<version>")
implementation("com.kape.platformsdk:kape-platform-sdk-openvpn:<version>")
}

Gradle (Groovy DSL)​

// settings.gradle
dependencyResolutionManagement {
repositories {
maven {
url "https://dl.cloudsmith.io/basic/expressvpn/kp_platform_sdks/maven/"
credentials {
username "token"
password "<YOUR_ENTITLEMENT_TOKEN>"
}
}
}
}
// app/build.gradle
dependencies {
implementation 'com.kape.platformsdk:kape-platform-sdk:<version>'
// One per VPN protocol the app supports — pass the matching object to KapeVpnManager
implementation 'com.kape.platformsdk:kape-platform-sdk-wireguard:<version>'
implementation 'com.kape.platformsdk:kape-platform-sdk-lightway:<version>'
implementation 'com.kape.platformsdk:kape-platform-sdk-openvpn:<version>'
}
info

The Low Level SDK (KapeClientSDK) AAR is included as a transitive dependency. You do not need to add it separately.

Kotlin version​

The SDK is compiled so that an app building with Kotlin 2.1.0 or later can use it. Every published module declares kotlin-stdlib 2.1.0 and carries Kotlin 2.1 metadata, whichever Kotlin version the SDK itself is built with. Raising that minimum is announced in the changelog.

The Lightway modules are the exception. kape-vpn-lightway, kape-vpn-lightway-bridge and kape-platform-sdk-lightway expose the Lightway library, which currently needs Kotlin 2.3 or later. Compiling against them with an older Kotlin fails with Module was compiled with an incompatible version of Kotlin.

kape-vpn-openvpn, kape-vpn-openvpn-bridge and kape-platform-sdk-openvpn compile with Kotlin 2.1, but the OpenVPN library they include raises the app's kotlin-stdlib to 2.2.

Choosing VPN protocols​

kape-platform-sdk contains no VPN protocol. Each protocol is a separate artifact carrying that protocol's tunnel and native libraries, so an app ships only the protocols it declares:

ProtocolArtifactPass to KapeVpnManager(protocols = ...)
WireGuardkape-platform-sdk-wireguardKapeWireGuardSupport
Lightwaykape-platform-sdk-lightwayKapeLightwaySupport
OpenVPNkape-platform-sdk-openvpnKapeOpenVpnSupport

Use the same <version> for all of them; each depends on kape-platform-sdk. See VPN Protocol for what happens when the selected protocol is not bundled.

Depending on a single module​

kape-platform-sdk is a fused library containing every module except the VPN protocols, which is what most apps want. If your product needs OpenVPN endpoint configuration but does not run the SDK's tunnel — handing the config to your own backend, to a third-party OpenVPN client, or to a file — depend on the discovery artifact alone instead:

dependencies {
implementation("com.kape.platformsdk:kape-vpn-discovery:<version>")
}

It depends on kape-core only, so an app that depends on it links no WireGuard, OpenVPN or Lightway native library and ships none of them in its APK. See OpenVPN Endpoint Discovery.

Configuration File​

Create src/main/assets/KapeSDK.json in your app module. It is the same format the iOS SDK reads: the Platform SDK's settings sit at the top level, and the Kape Client SDK's configuration — provided to you — sits under client_sdk:

{
"client_id": "your-oidc-client-id",
"issuer_url": "https://auth.example.com/realms/your-tenant",
"redirect_url": "your-app-scheme://callback",
"license": "your-license-key",
"lightway_certificate": "-----BEGIN CERTIFICATE-----\nMIIG…\n-----END CERTIFICATE-----\n",
"client_sdk": {
"brand_id": "your-brand-id",
"environment": "Production",
"max_log_level": "Info",
"domains": { "srs_api_domain": "https://api.example.com/srs2/" }
}
}
KeyRequiredDescription
client_idOIDC onlyOIDC client ID
issuer_urlOIDC onlyOIDC issuer URL for discovery
redirect_urlOIDC onlyOIDC redirect URI (must match your manifest intent filter)
licenseNoSDK license key provided to you. Which features it grants gates parts of the SDK — see Licensed features below
lightway_certificateNoLightway CA certificate PEM. Required when using the Lightway protocol.
openvpn_ca_certificateNoOpenVPN CA chain PEM. Required when using the OpenVPN protocol.
openvpn_client_certificateNoOpenVPN client certificate PEM. Required when using the OpenVPN protocol.
openvpn_client_keyNoClient private key PEM. Required when using the OpenVPN protocol.
openvpn_tls_auth_keyNoOpenVPN TLS-Auth static key PEM. Required when using the OpenVPN protocol.
storage_nameNoName of the on-device storage holding the SDK session, auth state and cache (default: kape_sdk_storage). Give two configurations different names to keep separate sessions in one app — e.g. a production and a staging build variant. Letters, digits, ., _ and - only. Changing it on an existing install starts a new, signed-out session. Android only — the counterpart of the iOS keychain_service key.
file_logging_enabledNotrue writes the SDK's logs to disk, so they survive the process and can be uploaded or exported with KapeLogsCollector (default: false). Needs client_sdk.max_log_level Info or more verbose. See Logs Collector
logs_collectorNoSize and retention limits for the Low Level SDK's log files: prelog_max_mb, prelog_max_minutes, logfile_max_mb, log_retention_hours. See Logs Collector
client_sdkYesThe Kape Client SDK configuration, handed to it unchanged
client_sdk.brand_idYesBrand identifier provided to you
client_sdk.environmentYesProduction or Staging
client_sdk.max_log_levelNoOff, Error, Warn, Info, Debug, Trace (default: Info)

PEM values are JSON strings, with each line break written as \n. brand_id, environment and max_log_level are read from client_sdk only, so each is set once for both SDKs.

Keys only the iOS SDK reads (app_group_identifier, keychain_service, packet_tunnel_bundle_identifier, server_address, vpn_profile_name, http_call_behavior) are ignored on Android, and iOS ignores storage_name — so one file can carry both platforms' keys.

Load the settings in code using:

val settings = KapeSDKSettings.fromJson(context) // assets/KapeSDK.json
val staging = KapeSDKSettings.fromJson(context, "KapeSDK-staging.json") // another asset
val fromString = KapeSDKSettings.fromJson(jsonString) // settings not shipped as an asset

A missing or malformed file throws IllegalStateException naming the problem, e.g. Required key 'client_sdk.brand_id' missing in the SDK settings.

"OIDC only" keys may be omitted if you sign users in only as guests or with an opaque token. An OIDC login without issuer_url or redirect_url returns LoginResult.AuthError whose cause is a KapeError in the Configuration domain naming the key. A value that is present but not a URI still throws Invalid URI for '<key>' in the SDK settings.

Migrating from kape_sdk_settings.xml and a YAML file​

Earlier versions read res/xml/kape_sdk_settings.xml, which named a YAML file and PEM files in assets/. That format is still read by KapeSDKSettings.fromXml(context, R.xml.kape_sdk_settings). To move to KapeSDK.json, put the YAML file's content under client_sdk (as JSON) and map the attributes:

XML attributeKapeSDK.json key
brand-idclient_sdk.brand_id
environmentclient_sdk.environment
max-log-levelclient_sdk.max_log_level
client-idclient_id
issuer-urlissuer_url
redirect-urlredirect_url
licenselicense
yaml-config-name— (the YAML content is client_sdk)
lightway-certificate[-asset]lightway_certificate (the PEM itself)
openvpn-ca-certificate[-asset]openvpn_ca_certificate
openvpn-client-certificate[-asset]openvpn_client_certificate
openvpn-client-key[-asset]openvpn_client_key
openvpn-tls-auth-key[-asset]openvpn_tls_auth_key
storage-namestorage_name
file-logging-enabledfile_logging_enabled (a JSON boolean)
prelog-max-mb, prelog-max-minutes, log-file-max-mb, log-retention-hourslogs_collector.prelog_max_mb, .prelog_max_minutes, .logfile_max_mb, .log_retention_hours (JSON numbers)

The XML's max-log-level was applied after the YAML's max_log_level, so keep the XML value. The Low Level SDK read brand_id and environment from the YAML only, defaulting to xv and Production when the YAML had none — use those values to keep the same behaviour.

Licensed features​

Your SDK license carries the set of features it grants. Seventeen of them gate SDK behaviour:

FeatureGates
CategoryDedicatedIpDedicated IP. Without it every KapeDipAccountService read reports the same thing a subscription with no Dedicated IP licenses reports — KapeDipSetupStage.NotEntitled, empty location lists — setup calls return DipSetupResult.NotEntitled, and KapeVpnManager.connect(location) on a Dedicated IP returns ConnectResult.DipError(KapeVpnTunnelError.DipNotEntitled). Nothing to handle beyond what you already handle for an unentitled subscription
CategorySimpleDedicatedIpSimple Dedicated IPs in fetchDedicatedIps, and reserving one. Without it they are left out of the list, with no error, and reserveSimpleDip returns NotEntitled
VpnProtocolLightwaysetSelectedProtocol(Lightway), and Lightway endpoints under Automatic
VpnProtocolWireGuardsetSelectedProtocol(Wireguard), and WireGuard endpoints under Automatic
VpnProtocolOpenVpnsetSelectedProtocol(OpenVPN), and OpenVPN endpoints under Automatic
VpnProtocolObfuscationObfuscated endpoints. Filters rather than refuses — see below
VpnLightwayBitripplesetBitrippleEnabled
VpnLightwaySnisetLightwaySNI
VpnHttpsProxysetProxyConfig
VpnKillSwitchAdvancedsetKillSwitchMode(Advanced) only
VpnSplitTunnelsetSplitTunnelAppMode and the per-package edits
VpnCustomDnssetCustomDnsServers
VpnAdvancedProtectionsetAdvancedProtectionCategories
VpnLightwayHeartbeatsetHeartbeatEnabled
VpnLightwayExpresslanesetExpresslaneEnabled
VpnSessionPauseResumepause. resume is never gated
VpnAutoConnectRulessetConnectOnDemand, setOnDemandRules and the rule edit helpers, plus setConnectOnStartup

See Licensed VPN features for what each refusal looks like and how a license downgrade or expiry is handled.

KapeSdkHandle.hasLicensedFeature(feature) reports what your license grants, so you can hide UI for a feature you are not licensed for. The verdict comes from the Low Level SDK's own licenseStatus() — it has verified the license signature and read its expiry date, and it remains the authority, enforcing licensing itself on every request.

It is not available synchronously at startup. licenseStatus() needs the Low Level SDK's manager, which KapeSdkHandle builds in the background, so hasLicensedFeature returns false until that finishes. Bind UI to KapeSdkHandle.licenseState instead, which starts at KapeLicenseState.Resolving and emits KapeLicenseState.Resolved once the verdict is known — a bare false cannot tell "not known yet" from "not granted". awaitLicensedFeature(feature) is the suspending one-shot form.

when (val state = handle.licenseState.collectAsState().value) {
is KapeLicenseState.Resolving -> showPlaceholder()
is KapeLicenseState.Resolved -> {
showSplitTunnelUi(state.isLicensed(LicensedFeature.VpnSplitTunnel))
// Any problem grants nothing — an expired or revoked license reports it here.
state.problems.forEach { log(it.toString()) }
}
}

Manifest Setup​

AppAuth's RedirectUriReceiverActivity must be able to intercept your redirect URI scheme. There are two ways to configure this.

Option A: Gradle placeholder (recommended). Set appAuthRedirectScheme in your build.gradle.kts. AppAuth's own manifest entry already uses this placeholder, so no changes to AndroidManifest.xml are needed:

// app/build.gradle.kts
android {
defaultConfig {
manifestPlaceholders["appAuthRedirectScheme"] = "your-app-scheme"
}
}

The value must be the scheme part of your redirect_url (e.g. "myapp" for myapp://callback).

Option B: Manual intent filter. Declare the intent filter directly in AndroidManifest.xml:

<activity
android:name="net.openid.appauth.RedirectUriReceiverActivity"
android:exported="true"
tools:node="replace">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="your-app-scheme" android:host="callback" />
</intent-filter>
</activity>

The scheme and host must match the redirect_url value in KapeSDK.json.

VPN Service Setup​

VPN connectivity (the KapeVpn module) runs the tunnel inside an android.net.VpnService. The service is an ordinary component of your app. Register it and declare the supporting permissions in your AndroidManifest.xml.

Declare the permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- Android 14 (API 34)+ -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<!-- Android 13 (API 33)+, for the foreground-service notification -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Register the service. The system requires the BIND_VPN_SERVICE permission on the <service> element and the android.net.VpnService intent filter:

<service
android:name=".KapeVpnTunnelService"
android:permission="android.permission.BIND_VPN_SERVICE"
android:foregroundServiceType="specialUse"
android:exported="false">
<intent-filter>
<action android:name="android.net.VpnService" />
</intent-filter>
</service>
info

Reading the current WiFi SSID for Smart Locations and SSID-based on-demand rules additionally requires the ACCESS_FINE_LOCATION and ACCESS_BACKGROUND_LOCATION runtime permissions (and, on API 33+, NEARBY_WIFI_DEVICES). These are requested by your app only if you use those features. They are not bundled in the SDK's manifest — only the non-sensitive ACCESS_WIFI_STATE is. See Server Locations and Network Protection.

The SDK also contributes one component of its own to your merged manifest: KapeOnDemandService, a foreground service that keeps Connect on Demand watching while no tunnel is running. It does nothing until Connect on Demand is enabled. Reacting to a reboot is your own receiver's job — see Network Protection.

See VPN Service for the KapeVpnTunnelService implementation.

OpenVPN Build Configuration​

When using the OpenVPN protocol, the OpenVPN binary (libovpnexec.so) is executed as a subprocess and must be extracted to the filesystem on install. Enable legacy JNI packaging in your build.gradle.kts:

// app/build.gradle.kts
android {
packaging {
jniLibs {
useLegacyPackaging = true
}
}
}

Without this, libovpnexec.so remains compressed inside the APK and cannot be executed, causing OpenVPN connections to fail at startup.