diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 336464ba..0d5c8290 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,6 +17,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + submodules: 'true' - name: Prepare build dir run: | @@ -62,7 +64,6 @@ jobs: cd ${{ github.workspace }}/build/AndroidLibV2rayLite bash compile-tun2socks.sh tar -xvzf libtun2socks.so.tgz - cp -r libs/* ${{ github.workspace }}/V2rayNG/app/libs/ env: NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} @@ -75,7 +76,7 @@ jobs: - name: Copy libtun2socks run: | - cp -r ${{ github.workspace }}/build/AndroidLibV2rayLite/libs/* ${{ github.workspace }}/V2rayNG/app/libs/ + cp -r ${{ github.workspace }}/build/AndroidLibV2rayLite/libs ${{ github.workspace }}/V2rayNG/app - name: Download libv2ray uses: robinraju/release-downloader@v1 @@ -85,6 +86,44 @@ jobs: fileName: 'libv2ray.aar' out-file-path: V2rayNG/app/libs/ + - name: Restore cached libhysteria2 + id: cache-libhysteria2-restore + uses: actions/cache/restore@v4 + with: + path: ${{ github.workspace }}/hysteria/libs + key: libhysteria2-${{ runner.os }}-${{ hashFiles('.git/modules/hysteria/HEAD') }}-${{ hashFiles('libhysteria.sh') }} + + - name: Fetch Go version from AndroidLibXrayLite + if: steps.cache-libhysteria2-restore.outputs.cache-hit != 'true' + run: | + GO_VERSION=$(curl -sL https://github.com/2dust/AndroidLibXrayLite/raw/refs/heads/main/go.mod | sed -n -E 's/.*go ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p') + echo "Go version: $GO_VERSION" + echo "GO_VERSION=$GO_VERSION" >> $GITHUB_ENV + + - name: Setup Golang + if: steps.cache-libhysteria2-restore.outputs.cache-hit != 'true' + uses: actions/setup-go@v5 + with: + go-version: '${{ env.GO_VERSION }}' + + - name: Build libhysteria2 + if: steps.cache-libhysteria2-restore.outputs.cache-hit != 'true' + run: | + bash libhysteria2.sh + env: + ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} + + - name: Save libhysteria2 + if: steps.cache-libhysteria2-restore.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ${{ github.workspace }}/hysteria/libs + key: libhysteria2-${{ runner.os }}-${{ hashFiles('.git/modules/hysteria/HEAD') }}-${{ hashFiles('libhysteria.sh') }} + + - name: Copy libhysteria2 + run: | + cp -r ${{ github.workspace }}/hysteria/libs ${{ github.workspace }}/V2rayNG/app + - name: Setup Java uses: actions/setup-java@v4 with: diff --git a/.gitignore b/.gitignore index 239dde7f..b844412d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,4 @@ V2rayNG/app/release/output.json .idea/ .gradle/ -libtun2socks.so -libhysteria2.so \ No newline at end of file +*.so diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..b0a1e97d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "hysteria"] + path = hysteria + url = https://github.com/apernet/hysteria diff --git a/V2rayNG/app/libs/arm64-v8a/libhysteria2.so b/V2rayNG/app/libs/arm64-v8a/libhysteria2.so deleted file mode 100644 index 9de1a377..00000000 Binary files a/V2rayNG/app/libs/arm64-v8a/libhysteria2.so and /dev/null differ diff --git a/V2rayNG/app/libs/armeabi-v7a/libhysteria2.so b/V2rayNG/app/libs/armeabi-v7a/libhysteria2.so deleted file mode 100644 index ac5e7379..00000000 Binary files a/V2rayNG/app/libs/armeabi-v7a/libhysteria2.so and /dev/null differ diff --git a/V2rayNG/app/libs/x86/libhysteria2.so b/V2rayNG/app/libs/x86/libhysteria2.so deleted file mode 100644 index 1a6eb668..00000000 Binary files a/V2rayNG/app/libs/x86/libhysteria2.so and /dev/null differ diff --git a/V2rayNG/app/libs/x86_64/libhysteria2.so b/V2rayNG/app/libs/x86_64/libhysteria2.so deleted file mode 100644 index 4ae0497e..00000000 Binary files a/V2rayNG/app/libs/x86_64/libhysteria2.so and /dev/null differ diff --git a/hysteria b/hysteria new file mode 160000 index 00000000..15e31d48 --- /dev/null +++ b/hysteria @@ -0,0 +1 @@ +Subproject commit 15e31d48a09af0835773bd5c62cedbb3fc0e351d diff --git a/libhysteria2.sh b/libhysteria2.sh new file mode 100644 index 00000000..5c0d6fd0 --- /dev/null +++ b/libhysteria2.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +targets=( + "aarch64-linux-android21 arm64 arm64-v8a" + "armv7a-linux-androideabi21 arm armeabi-v7a" + "x86_64-linux-android21 amd64 x86_64" + "i686-linux-android21 386 x86" +) + +cd "hysteria" || exit + +for target in "${targets[@]}"; do + IFS=' ' read -r ndk_target goarch abi <<< "$target" + + echo "Building for ${abi} with ${ndk_target} (${goarch})" + + CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/${ndk_target}-clang" CGO_ENABLED=1 CGO_LDFLAGS="-Wl,-z,max-page-size=16384" GOOS=android GOARCH=$goarch go build -o libs/$abi/libhysteria2.so -trimpath -ldflags "-s -w -buildid=" ./app + + echo "Built libhysteria2.so for ${abi}" +done