Skip to content

getlantern/lanternsdk-android

Repository files navigation

Lantern SDK for Android

The Lantern SDK provides a way for developers and third parties to integrate Lantern and access its infrastructure for censorship circumvention. The SDK is designed to work with network APIs that respect the default ProxySelector. It integrates with Lantern’s core proxying functionality and offers a Kotlin-friendly API for easy integration.

Overview

  • lantern: The core Go logic for configuring and launching Lantern (via Flashlight)
  • sdk: The SDK module that wraps the Go functions in a Kotlin-friendly interface
  • example: Demonstrates how to integrate the Lantern SDK in an actual Android application

Getting Started

Build the Lantern SDK

The following command builds both the Lantern core library and the Android SDK:

make build-sdk

This will produce the SDK as an .aar file located at ./build/lanternsdk-android.aar.

The .aar file contains the compiled Go library and Kotlin bindings, ready for integration into your Android app.

Integrating the Lantern SDK

  1. Add the SDK to Your Project

Copy the lanternsdk-android.aar file to your app’s libs/ directory and update your app’s build.gradle:

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    implementation(name: 'lanternsdk-android', ext: 'aar')
}
  1. Initialize Lantern

Before starting the Lantern proxy, initialize the SDK with your app name and configuration directory:

import io.lantern.sdk.LanternManager


val context: Context = // ...
LanternManager.setup(context, "HelloVPN", "HelloVPN/config")

If no configuration directory is provided, the configuration files will be stored securely in the app’s internal storage.

  1. Start the Lantern Proxy

Start Lantern with the desired proxy configuration:

import io.lantern.sdk.LanternManager

val proxyAddr = ":8080"  // Proxy address
val proxyAllTraffic = true // Set to true to proxy all traffic

LanternManager.startLantern(proxyAddr, proxyAllTraffic)

After starting Lantern, it will be set as the system proxy and all HTTP traffic will be proxied. This method returns the address the proxy is listening. If the proxy fails to start, it returns an error.

  1. Stop the Lantern Proxy

To stop actively proxying traffic:

LanternManager.stopLantern()

Lantern will continue running in the background to update its configuration but will no longer proxy traffic.