Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK updates: Use latest Go library, update gradle, and CI/CD integration #3

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build and Publish SDK

on:
push:
branches:
- atavism/update-sdk
tags:
- 'v*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
lfs: true

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '^1.22.4'

- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: 'gradle'

- name: Build Production SDK
run: make release
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lantern"]
path = lantern
url = https://github.com/getlantern/lantern-client
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
SDK_NAME := liblantern
SDK_DIR := sdk
GO_LIB_PATH := lantern
AAR_OUTPUT := lanternsdk-android.aar
LIBS_DIR := $(SDK_DIR)/libs
BUILD_DIR := build
PROD_FLAG := -ldflags "-s -w"
GRADLEW := ./gradlew
EXAMPLE_PROJECT := :example

.PHONY: build release clean publish example-debug

update-lantern-lib:
git submodule update --init --recursive --remote

build:
@echo "Building Lantern library..."
cd $(GO_LIB_PATH) && \
make android-sdk && \
echo "Copying AAR to $(LIBS_DIR)..."
mkdir -p $(LIBS_DIR)
cp $(GO_LIB_PATH)/$(SDK_NAME)-all.aar $(LIBS_DIR)/$(AAR_OUTPUT)

# Build SDK release
release:
@echo "Building production SDK.."
$(GRADLEW) clean assembleRelease

sdk-debug:
$(GRADLEW) clean :$(SDK_DIR):assembleDebug

example-debug:
$(GRADLEW) clean $(EXAMPLE_PROJECT):assembleDebug

clean:
rm -rf $(LIBS_DIR)/$(AAR_OUTPUT)
rm -rf $(BUILD_DIR)
61 changes: 42 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,57 @@ else.

## Usage

### Starting Lantern
After starting Lantern, all HTTP traffic will be proxied.
### Build Lantern library

```java
import android.content.Context;
import io.lantern.sdk.Lantern;
To build and import the compiled Go code for the Lantern library, run the following command:

...
```bash
make build
```

### Setting up Lantern

To setup your app to integrate Lantern, you should first specify some initial configuration for the
SDK to use, including the app name and configuration directory.

Context context = ...;
String appName = "your app name assigned by Lantern";
long startTimeoutMillis = 60000; // 60 seconds
bool proxyAllTraffic = true;
Lantern.start(context, appName, proxyAllTraffic, startTimeoutMillis);
```kotlin
import android.content.Context
import io.lantern.sdk.Lantern

Lantern.setup("HelloVPN", "HelloVPN/config")
```

### Stopping Lantern
After stopping Lantern, Lantern will continue to run in the background to keep fetching updated
configuration maintain its state, but no traffic will be proxied.
### Starting Lantern

```kotlin
import android.content.Context
import io.lantern.sdk.Lantern

...
Lantern.stop();
val context: Context = ...
val appName = "your app name assigned by Lantern"
val proxyAddr = ":8080"
val startTimeoutMillis = 60000L // 60 seconds
val proxyAllTraffic = true
Lantern.start(context, appName, proxyAddr, proxyAllTraffic, startTimeoutMillis)
```

### Starting Lantern Again
Lantern can be started again after stopping it. This will be a fast start since Lantern is already
running.
After starting Lantern, it will be set as the system proxy and all HTTP traffic will be proxied.
This method blocks up til the given timeout and returns the address the proxy is listening. If the proxy doesn't start within the given timeout, it returns an error.

### Stopping Lantern

```kotlin
Lantern.stop()
```
Lantern.start(context, appName, startTimeoutMillis);

After stopping Lantern, Lantern will continue to run in the background to keep fetching updated
configuration maintain its state, but no traffic will be proxied.

### Restart Lantern
Lantern can be restarted after stopping it. This will be a fast start since Lantern is already
running

```kotlin
Lantern.restart(context, startTimeoutMillis)
```
20 changes: 15 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.32"
ext.kotlin_version = "2.0.20"
ext.ktor_version = "1.5.2"

repositories {
Expand All @@ -10,13 +10,19 @@ buildscript {
maven {
url "https://plugins.gradle.org/m2/"
}
maven {
setUrl("https://jitpack.io")
content {
includeGroup("com.github.aasitnikov")
}
}
}

dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath "com.android.tools.build:gradle:8.6.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath("org.jlleitschuh.gradle:ktlint-gradle:10.0.0")
classpath 'com.kezong:fat-aar:1.3.3'
classpath("org.jlleitschuh.gradle:ktlint-gradle:11.3.1")
classpath 'com.github.aasitnikov:fat-aar-android:1.4.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -32,10 +38,14 @@ allprojects {
dirs 'libs'
}
}

apply plugin: "org.jlleitschuh.gradle.ktlint"
}

rootProject.buildDir = 'build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}

task clean(type: Delete) {
delete rootProject.buildDir
}
1 change: 1 addition & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
75 changes: 75 additions & 0 deletions example/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
namespace 'org.getlantern.lantern.sdk.example'
ndkVersion "27.0.12077973"
compileSdkVersion 35

defaultConfig {
applicationId "org.getlantern.lantern.sdk.example"
minSdkVersion 23
targetSdkVersion 34
versionCode 1
versionName "1.0"
multiDexEnabled true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

useLibrary 'org.apache.http.legacy'

compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
coreLibraryDesugaringEnabled = true
}

kotlinOptions {
jvmTarget = '17'
}

buildFeatures {
dataBinding true
viewBinding true
}
packaging {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}

repositories {
flatDir {
dirs 'libs/'
}
}


dependencies {

//implementation project(':sdk')
implementation files('libs/sdk-debug.aar')
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.3'
implementation fileTree(dir: "libs", include: ["*.jar"])

implementation 'androidx.core:core-ktx:1.15.0'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'com.squareup.okhttp3:okhttp:4.11.0'

testImplementation 'junit:junit:4.13.2'

androidTestImplementation 'androidx.test:runner:1.6.2'
androidTestImplementation 'androidx.test:rules:1.6.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'com.squareup.okhttp3:okhttp:4.9.2'

}
21 changes: 21 additions & 0 deletions example/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.getlantern.lantern.sdk.example

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("org.getlantern.lantern.sdk.example", appContext.packageName)
}
}
Loading
Loading