Skip to content

Latest commit

 

History

History
64 lines (52 loc) · 2.29 KB

singbox_build_android.md

File metadata and controls

64 lines (52 loc) · 2.29 KB

Here's the updated step-by-step guide with the additional step to create the output directory:

  1. Install Go:

    curl -sLo go.tar.gz https://go.dev/dl/go1.20.1.linux-amd64.tar.gz
    tar -C /usr/local -xzf go.tar.gz
    rm go.tar.gz
    export PATH=$PATH:/usr/local/go/bin
    go version
    
  2. Install Git:

    apt install -y git
    
  3. Clone the Sing-box repository:

    git clone https://github.com/SagerNet/sing-box.git
    cd sing-box
    
  4. Download and set up Android NDK:

    cd ~
    wget https://dl.google.com/android/repository/android-ndk-r21d-linux-x86_64.zip
    unzip android-ndk-r21d-linux-x86_64.zip
    ndk-build --version
    
  5. Configure the environment variables:

    nano .bashrc
    

    Scroll to the bottom of the file and add the following lines:

    export ANDROID_NDK=/opt/android-ndk
    export ANDROID_SDK=/opt/android-sdk
    export PATH=$PATH:$ANDROID_SDK/platform-tools:$ANDROID_SDK/tools:$ANDROID_NDK
    

    Save the changes and exit the text editor. In nano, you can do this by pressing Ctrl+X, then Y, then Enter.

  6. Apply the changes to the current session:

    source .bashrc
    
  7. Create the output directory:

    cd sing-box
    mkdir -p release/android/arm64-v8a/
    
  8. Build Sing-box for Android:

    GOOS=android GOARCH=arm64 CGO_ENABLED=1 CC=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang CXX=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++ go build -trimpath -ldflags="-s -w" -buildmode=pie -tags "with_quic with_wireguard with_ech with_utls with_reality_server" -o ./release/android/arm64-v8a/sing-box ./cmd/sing-box
    

After following these steps, the Sing-box binary for Android will be located at ./release/android/arm64-v8a/sing-box.

By adding the step to create the output directory (mkdir -p release/android/arm64-v8a/) before running the go build command, you ensure that the directory exists and the binary can be saved correctly.

Remember to replace the build tags (with_quic with_wireguard with_ech with_utls with_reality_server) with the desired tags for your Sing-box build, and ensure that you have the necessary dependencies and tools installed, such as the Android SDK and NDK, before proceeding with the build process.