diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bb21d99de..f6d546f5a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -62,7 +62,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 }} @@ -85,6 +84,41 @@ 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: | + cd ${{ github.workspace }}/hysteria + go build -v -o libs/$FOLDER/libhysteria2.so -trimpath -ldflags "-s -w -buildid=" ./app + env: + ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} + + - name: Save libhysteria2 + if: steps.cache-libtun2socks-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: Setup Java uses: actions/setup-java@v4 with: diff --git a/libhysteria2.sh b/libhysteria2.sh new file mode 100644 index 000000000..dd3277fc0 --- /dev/null +++ b/libhysteria2.sh @@ -0,0 +1,26 @@ +#!/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" +) + +for target in "${targets[@]}"; do + IFS=' ' read -r ndk_target goarch abi <<< "$target" + + 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 + FOLDER=$abi + + echo "Building for ${abi} with ${ndk_target} (${goarch})" + + cd "hysteria" || exit + go build -v -o libs/$FOLDER/libhysteria2.so -trimpath -ldflags "-s -w -buildid=" ./app + + echo "Built libhysteria2.so for ${abi}" +done