Skip to content

Conversation

@itsalfredakku
Copy link
Member

This pull request introduces a comprehensive build guide for the project and significantly enhances the Android build script. The main improvements are the addition of detailed multi-platform build instructions and the refactoring and extension of the build-android.sh script to support more flexible and robust Android builds, including per-architecture and auto-detected builds.

Documentation:

  • Added a complete BUILD.md file with step-by-step instructions for building on Android, iOS, and desktop, including troubleshooting and architecture references.

Android Build Script Enhancements (scripts/build-android.sh):

Environment Configuration:

  • Refactored environment variable setup to use a TOOLCHAIN variable, reducing duplication and making the configuration of linker, compiler, and archiver paths for all Android architectures more maintainable. [1] [2]

Build Options and Automation:

  • Added build_android_armv7 and build_android_auto functions to enable building for only 32-bit ARM (armeabi-v7a) or automatically detect and build for the architecture of a connected Android device.
  • Updated the script's command-line interface to support new commands: auto (auto-detect device architecture) and armv7 (build only for 32-bit ARM).

Usability Improvements:

  • Improved output and logging, and ensured built libraries are copied to the correct jniLibs directories for integration with Android apps.

These changes make the build process more user-friendly, flexible, and robust across different platforms and device architectures.

…figuration and add auto-detection for connected devices
Copilot AI review requested due to automatic review settings January 11, 2026 07:08
@itsalfredakku itsalfredakku merged commit 14b2964 into master Jan 11, 2026
20 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Android build workflow by refactoring the build script to use a centralized TOOLCHAIN variable and adding new build modes. It also introduces comprehensive build documentation covering Android, iOS, and desktop platforms.

Changes:

  • Refactored environment variable setup in build-android.sh to use a TOOLCHAIN variable, reducing code duplication
  • Added build_android_armv7 and build_android_auto functions for targeted builds and auto-detection of connected device architecture
  • Created comprehensive BUILD.md documentation with step-by-step instructions, architecture references, and troubleshooting guidance

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
scripts/build-android.sh Refactored toolchain configuration, added armv7 and auto-detection build functions, improved environment setup
BUILD.md Added complete multi-platform build guide with prerequisites, commands, architecture mappings, and troubleshooting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +269 to +282
x86)
log_info "Building for x86..."
rustup target add i686-linux-android
NDK_HOST=$(get_ndk_host)
LINKER_EXT=$(get_linker_ext)
TOOLCHAIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$NDK_HOST/bin"
export CARGO_TARGET_I686_LINUX_ANDROID_LINKER="$TOOLCHAIN/i686-linux-android21-clang$LINKER_EXT"
export CC_i686_linux_android="$TOOLCHAIN/i686-linux-android21-clang$LINKER_EXT"
export AR_i686_linux_android="$TOOLCHAIN/llvm-ar"
cargo build --release --target i686-linux-android --features android
mkdir -p target/android/jniLibs/x86 ../app/src/main/jniLibs/x86
cp target/i686-linux-android/release/libsoftether.so target/android/jniLibs/x86/
cp target/android/jniLibs/x86/libsoftether.so ../app/src/main/jniLibs/x86/ 2>/dev/null || true
;;
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The x86 case in build_android_auto does not validate that ANDROID_NDK_HOME is set before using it in the TOOLCHAIN variable. This could lead to an unclear error if ANDROID_NDK_HOME is not configured. Consider adding the same validation check that exists in build_android_arm64 and build_android_armv7 functions.

Copilot uses AI. Check for mistakes.
### Step 7: Build and Install APK

```bash
cd .. # Back to WorxVPN-Android root
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment references "WorxVPN-Android root" but the documentation refers to the project as "SoftEtherRust" throughout. This inconsistency could confuse users about the actual project name and directory structure. Consider using "SoftEtherRust" or the actual parent directory name consistently.

Suggested change
cd .. # Back to WorxVPN-Android root
cd .. # Back to Android project root

Copilot uses AI. Check for mistakes.
Comment on lines +255 to +282
x86_64)
log_info "Building for x86_64..."
rustup target add x86_64-linux-android
NDK_HOST=$(get_ndk_host)
LINKER_EXT=$(get_linker_ext)
TOOLCHAIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$NDK_HOST/bin"
export CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="$TOOLCHAIN/x86_64-linux-android21-clang$LINKER_EXT"
export CC_x86_64_linux_android="$TOOLCHAIN/x86_64-linux-android21-clang$LINKER_EXT"
export AR_x86_64_linux_android="$TOOLCHAIN/llvm-ar"
cargo build --release --target x86_64-linux-android --features android
mkdir -p target/android/jniLibs/x86_64 ../app/src/main/jniLibs/x86_64
cp target/x86_64-linux-android/release/libsoftether.so target/android/jniLibs/x86_64/
cp target/android/jniLibs/x86_64/libsoftether.so ../app/src/main/jniLibs/x86_64/ 2>/dev/null || true
;;
x86)
log_info "Building for x86..."
rustup target add i686-linux-android
NDK_HOST=$(get_ndk_host)
LINKER_EXT=$(get_linker_ext)
TOOLCHAIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$NDK_HOST/bin"
export CARGO_TARGET_I686_LINUX_ANDROID_LINKER="$TOOLCHAIN/i686-linux-android21-clang$LINKER_EXT"
export CC_i686_linux_android="$TOOLCHAIN/i686-linux-android21-clang$LINKER_EXT"
export AR_i686_linux_android="$TOOLCHAIN/llvm-ar"
cargo build --release --target i686-linux-android --features android
mkdir -p target/android/jniLibs/x86 ../app/src/main/jniLibs/x86
cp target/i686-linux-android/release/libsoftether.so target/android/jniLibs/x86/
cp target/android/jniLibs/x86/libsoftether.so ../app/src/main/jniLibs/x86/ 2>/dev/null || true
;;
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The x86_64 and x86 cases inline directory creation and file copying logic, creating code duplication compared to build_android_arm64 and build_android_armv7 functions which follow a consistent pattern. Consider extracting these cases into separate functions like build_android_x86_64 and build_android_x86 for better maintainability and consistency.

Copilot uses AI. Check for mistakes.
export CC_x86_64_linux_android="$TOOLCHAIN/x86_64-linux-android21-clang$LINKER_EXT"
export AR_x86_64_linux_android="$TOOLCHAIN/llvm-ar"
cargo build --release --target x86_64-linux-android --features android
mkdir -p target/android/jniLibs/x86_64 ../app/src/main/jniLibs/x86_64
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mkdir command creates multiple directories in a single command including the app directory which may not exist. If the parent directory "../app/src/main" doesn't exist, this mkdir will fail. Consider separating the directory creation for target and app directories, or checking for the app directory existence first (similar to the pattern used in build_android_arm64 and build_android_armv7).

Copilot uses AI. Check for mistakes.
export CC_i686_linux_android="$TOOLCHAIN/i686-linux-android21-clang$LINKER_EXT"
export AR_i686_linux_android="$TOOLCHAIN/llvm-ar"
cargo build --release --target i686-linux-android --features android
mkdir -p target/android/jniLibs/x86 ../app/src/main/jniLibs/x86
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mkdir command creates multiple directories in a single command including the app directory which may not exist. If the parent directory "../app/src/main" doesn't exist, this mkdir will fail. Consider separating the directory creation for target and app directories, or checking for the app directory existence first (similar to the pattern used in build_android_arm64 and build_android_armv7).

Copilot uses AI. Check for mistakes.
Comment on lines +255 to +268
x86_64)
log_info "Building for x86_64..."
rustup target add x86_64-linux-android
NDK_HOST=$(get_ndk_host)
LINKER_EXT=$(get_linker_ext)
TOOLCHAIN="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/$NDK_HOST/bin"
export CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="$TOOLCHAIN/x86_64-linux-android21-clang$LINKER_EXT"
export CC_x86_64_linux_android="$TOOLCHAIN/x86_64-linux-android21-clang$LINKER_EXT"
export AR_x86_64_linux_android="$TOOLCHAIN/llvm-ar"
cargo build --release --target x86_64-linux-android --features android
mkdir -p target/android/jniLibs/x86_64 ../app/src/main/jniLibs/x86_64
cp target/x86_64-linux-android/release/libsoftether.so target/android/jniLibs/x86_64/
cp target/android/jniLibs/x86_64/libsoftether.so ../app/src/main/jniLibs/x86_64/ 2>/dev/null || true
;;
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The x86_64 case in build_android_auto does not validate that ANDROID_NDK_HOME is set before using it in the TOOLCHAIN variable. This could lead to an unclear error if ANDROID_NDK_HOME is not configured. Consider adding the same validation check that exists in build_android_arm64 and build_android_armv7 functions.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants