OpenVPN transport

Configuring OpenVPN transport support on Android

If your Android project meets the following conditions:

Then you need to add the following line to your gradle.properties file to ensure OpenVPN transport works on Android 10 (Q) (API 29) and later versions:

android.bundle.enableUncompressedNativeLibs=false

If you are not using Google App Bundle for your application distribution, you can skip this step, as it is not required.

Adding OpenVPN transport support

  1. To add support for OpenVPN, you need to include both the core SDK and OpenVPN transport SDK in your build.gradle file:

dependencies {
    implementation 'co.pango:sdk-core:{VERSION_NAME}'
    implementation 'co.pango:sdk-openvpn:{VERSION_NAME}'
}
  • sdk-core: This is the core VPN SDK.

  • sdk-openvpn: This adds OpenVPN support to your app.

  1. Next, you need to register OpenVPN as a supported transport protocol with the SDK. You can register both Hydra and OpenVPN, or just one, depending on your requirements:

List<TransportConfig> transports = new ArrayList<>();
transports.add(HydraTransportConfig.create());
transports.add(OpenVpnTransportConfig.tcp());
UnifiedSDK.update(transportConfigs, callback);
  • HydraTransportConfig.create(): Registers Hydra transport (default).

  • OpenVpnTransportConfig.tcp(): Registers OpenVPN using TCP as the transport protocol.

  • UnifiedSDK.update(): Updates the SDK with the registered transport protocols.

You can register both Hydra and OpenVPN transports or just one of them.

3. When starting a VPN session, you can specify which transport protocol to use (Hydra or OpenVPN). Here’s how to specify OpenVPN (TCP) when starting the VPN:

UnifiedSdk sdk = UnifiedSdk.getInstance(clientInfo);
SessionInfo session = new SessionConfig.Builder()
                .withLocation(UnifiedSDK.COUNTRY_OPTIMAL)
                .withReason(TrackingConstants.GprReasons.M_UI)
                .withTransport(OpenVpnTransport.TRANSPORT_ID_TCP)
                .build();
sdk.getVpn().start(session, new CompletableCallback() {
    @Override
    public void complete() {

    }

    @Override
    public void error(@NonNull VpnException e) {

    }
});
  • SessionConfig.Builder(): Creates a configuration for the VPN session.

  • withLocation(): Specifies the VPN location (e.g., COUNTRY_OPTIMAL selects the best available server).

  • withReason(): Provides a reason for starting the VPN session (for analytics purposes).

  • withTransport(): Specifies the transport protocol to be used (OpenVPN TCP in this case).

  • sdk.getVpn().start(): Starts the VPN session with the specified configuration.

Last updated

Was this helpful?