Skip to content
Open
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
48 changes: 48 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Android CI

on:
push:
branches: [ master, elastic-curran ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive

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

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew assembleRelease --stacktrace

- name: Run tests
run: ./gradlew test --stacktrace

- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: app-release
path: app/build/outputs/apk/release/*.apk
retention-days: 7

- name: Build summary
run: |
echo "### Build Summary :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Status**: ✅ Success" >> $GITHUB_STEP_SUMMARY
echo "- **APK Location**: \`app/build/outputs/apk/release/\`" >> $GITHUB_STEP_SUMMARY
ls -lh app/build/outputs/apk/release/*.apk >> $GITHUB_STEP_SUMMARY || true
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,12 @@ proguard-sbt.txt

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Gradle wrapper JAR (optional - uncomment if you don't want to commit it)
# gradle/wrapper/gradle-wrapper.jar

# CMake build outputs
.cxx/

# Kotlin compiled files
*.kotlin_module
10 changes: 10 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
[submodule "src/main/jni/libev"]
path = src/main/jni/libev
url = https://github.com/shadowsocks/libev.git
[submodule "app/src/main/jni/simple-obfs"]
path = app/src/main/jni/simple-obfs
url = https://github.com/shadowsocks/simple-obfs.git
[submodule "app/src/main/jni/libev"]
path = app/src/main/jni/libev
url = https://github.com/shadowsocks/libev.git
[submodule "app/src/main/jni/libancillary"]
path = app/src/main/jni/libancillary
url = https://github.com/shadowsocks/libancillary.git
branch = shadowsocks-android
205 changes: 205 additions & 0 deletions MIGRATION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# Project Refactoring Summary

## Overview
This document summarizes the refactoring of simple-obfs-android from SBT/Scala to Gradle/Kotlin with CMake.

## Changes Made

### 1. Build System Migration: SBT → Gradle

#### Created Files:
- `build.gradle.kts` - Root project build configuration
- `settings.gradle.kts` - Project settings and module inclusion
- `gradle.properties` - Gradle build properties
- `app/build.gradle.kts` - App module build configuration
- `app/proguard-rules.pro` - ProGuard configuration for release builds
- `gradlew` - Gradle wrapper script (executable)
- `gradle/wrapper/gradle-wrapper.properties` - Gradle wrapper properties

#### Key Configuration:
- Gradle 8.5 with Kotlin DSL
- Android Gradle Plugin 8.2.0
- Kotlin Plugin 1.9.20
- Target SDK: 34 (Android 14)
- Min SDK: 19 (Android 4.4)
- Build Tools: Modern AndroidX libraries

#### Removed Files (obsolete):
- `build.sbt` - Old SBT build file (can be deleted)
- `project/build.properties` - Old SBT properties (can be deleted)
- `project/plugins.sbt` - Old SBT plugins (can be deleted)

### 2. Native Build Migration: Android.mk → CMake

#### Created Files:
- `app/src/main/cpp/CMakeLists.txt` - CMake build configuration for native code

#### Key Changes:
- Replaced `ndk-build` with CMake 3.22.1+
- Builds same native libraries:
- `libcork` (static)
- `libev` (static)
- `libancillary` (static)
- `libobfs-local.so` (shared executable)
- Maintains all compiler flags and definitions
- Support for armeabi-v7a, arm64-v8a, x86, x86_64

#### Preserved Files:
- `app/src/main/jni/*` - All native source code (kept in same location)
- `simple-obfs/` - Main obfuscation implementation
- `libev/` - Event loop library
- `libancillary/` - File descriptor passing
- `include/` - Header files

### 3. Language Migration: Scala → Kotlin

#### Converted Files:

| Original (Scala) | New (Kotlin) | Location |
|-----------------|--------------|----------|
| `BinaryProvider.scala` | `BinaryProvider.kt` | `app/src/main/kotlin/com/github/shadowsocks/plugin/obfs_local/` |
| `ConfigFragment.scala` | `ConfigFragment.kt` | `app/src/main/kotlin/com/github/shadowsocks/plugin/obfs_local/` |
| `ConfigActivity.scala` | `ConfigActivity.kt` | `app/src/main/kotlin/com/github/shadowsocks/plugin/obfs_local/` |

#### Key Conversions:
- `PreferenceFragment` → `PreferenceFragmentCompat` (AndroidX)
- Scala collections → Kotlin collections
- Scala lambda syntax → Kotlin lambda syntax
- Scala pattern matching → Kotlin when expressions
- Added null safety with Kotlin's type system

#### Old Files (can be deleted):
- `src/main/scala/com/github/shadowsocks/plugin/obfs_local/*.scala`

### 4. Resource Migration

#### Moved Files:
- `src/main/res/*` → `app/src/main/res/*`
- `src/main/AndroidManifest.xml` → `app/src/main/AndroidManifest.xml`

#### Added Files:
- `app/src/main/res/layout/toolbar_light_dark.xml` - Toolbar layout
- `app/src/main/res/values/themes.xml` - App theme definition

#### Updated Files:
- `app/src/main/res/values/strings.xml` - Added missing strings
- `app/src/main/AndroidManifest.xml` - Added theme attribute

### 5. Dependencies Update

#### Old (SBT):
```scala
libraryDependencies += "com.github.shadowsocks" %% "plugin" % "0.0.2"
```

#### New (Gradle):
```kotlin
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.preference:preference-ktx:1.2.1")
implementation("com.github.shadowsocks:plugin:0.0.2")
```

### 6. Documentation Updates

- `README.md` - Completely rewritten with Gradle/Kotlin build instructions
- `README_OLD.md` - Backup of original README (can be deleted after verification)
- `.gitignore` - Updated for Gradle/CMake build artifacts

## New Project Structure

```
simple-obfs-android/
├── app/
│ ├── build.gradle.kts # App module configuration
│ ├── proguard-rules.pro # ProGuard rules
│ └── src/main/
│ ├── AndroidManifest.xml # App manifest
│ ├── cpp/
│ │ └── CMakeLists.txt # CMake configuration
│ ├── jni/ # Native code (unchanged)
│ │ ├── simple-obfs/
│ │ ├── libev/
│ │ ├── libancillary/
│ │ └── include/
│ ├── kotlin/ # Kotlin source (new)
│ │ └── com/github/shadowsocks/plugin/obfs_local/
│ │ ├── BinaryProvider.kt
│ │ ├── ConfigActivity.kt
│ │ └── ConfigFragment.kt
│ └── res/ # Android resources
├── gradle/
│ └── wrapper/
│ └── gradle-wrapper.properties
├── build.gradle.kts # Root build config
├── settings.gradle.kts # Project settings
├── gradle.properties # Gradle properties
├── gradlew # Gradle wrapper (Unix)
└── README.md # Updated documentation
```

## Building the Project

### Before (SBT):
```bash
sbt clean android:package-release
```

### After (Gradle):
```bash
# Debug build
./gradlew assembleDebug

# Release build
./gradlew assembleRelease
```

## Testing the Migration

1. Initialize submodules:
```bash
git submodule update --init --recursive
```

2. Build debug APK:
```bash
./gradlew assembleDebug
```

3. Verify APK is generated:
```bash
ls -lh app/build/outputs/apk/debug/
```

## Cleanup Recommendations

After verifying the new build system works, you can safely delete:
- `build.sbt`
- `project/` directory
- `src/main/scala/` directory
- `README_OLD.md`

## Compatibility Notes

- The APK package name remains: `com.github.shadowsocks.plugin.obfs_local`
- Version code: 5
- Version name: 0.0.5
- All functionality preserved from Scala version
- Native library name unchanged: `libobfs-local.so`
- Plugin interface compatibility maintained

## Key Benefits

1. **Modern Tooling**: Gradle is the standard Android build system
2. **Better IDE Support**: Full Android Studio integration
3. **Kotlin Benefits**: Null safety, concise syntax, better Java interop
4. **CMake**: Industry-standard for C/C++ builds
5. **Maintainability**: Easier for new contributors familiar with modern Android development
6. **Performance**: Gradle's incremental builds and build cache
7. **Dependencies**: Access to Maven Central and Google's Android repositories

## Notes

- All native code (C) remains unchanged
- Plugin functionality is identical
- Compatible with same shadowsocks-android versions
- Git submodules preserved (simple-obfs, libev, etc.)
Loading