-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: Update build script for Android to streamline toolchain configuration and add auto-detection for connected devices #40
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
Conversation
…figuration and add auto-detection for connected devices
There was a problem hiding this 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.shto use a TOOLCHAIN variable, reducing code duplication - Added
build_android_armv7andbuild_android_autofunctions 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.
| 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 | ||
| ;; |
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
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.
| ### Step 7: Build and Install APK | ||
|
|
||
| ```bash | ||
| cd .. # Back to WorxVPN-Android root |
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
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.
| cd .. # Back to WorxVPN-Android root | |
| cd .. # Back to Android project root |
| 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 | ||
| ;; |
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
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.
| 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 |
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
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).
| 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 |
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
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).
| 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 | ||
| ;; |
Copilot
AI
Jan 11, 2026
There was a problem hiding this comment.
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.
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.shscript to support more flexible and robust Android builds, including per-architecture and auto-detected builds.Documentation:
BUILD.mdfile 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:
TOOLCHAINvariable, reducing duplication and making the configuration of linker, compiler, and archiver paths for all Android architectures more maintainable. [1] [2]Build Options and Automation:
build_android_armv7andbuild_android_autofunctions to enable building for only 32-bit ARM (armeabi-v7a) or automatically detect and build for the architecture of a connected Android device.auto(auto-detect device architecture) andarmv7(build only for 32-bit ARM).Usability Improvements:
jniLibsdirectories for integration with Android apps.These changes make the build process more user-friendly, flexible, and robust across different platforms and device architectures.