Here's the updated step-by-step guide with the additional step to create the output directory:
-
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
-
Install Git:
apt install -y git
-
Clone the Sing-box repository:
git clone https://github.com/SagerNet/sing-box.git cd sing-box
-
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
-
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.
-
Apply the changes to the current session:
source .bashrc
-
Create the output directory:
cd sing-box mkdir -p release/android/arm64-v8a/
-
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.