From 9090f83e4d14f7dab30e366787e3e2bf69881a1e Mon Sep 17 00:00:00 2001 From: UjuiUjuMandan <125150101+UjuiUjuMandan@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:09:46 +0000 Subject: [PATCH] matrix --- .github/workflows/build.yml | 175 ++++++++++++++++++++++++++++++----- V2rayNG/app/build.gradle.kts | 1 + 2 files changed, 154 insertions(+), 22 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6fdb6726b..bfe1aab02 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,22 @@ on: jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + abi: [arm64-v8a, armeabi-v7a, x86_64, x86] + include: + - abi: arm64-v8a + ndk_target: aarch64-linux-android21 + goarch: arm64 + - abi: armeabi-v7a + ndk_target: armv7a-linux-androideabi21 + goarch: arm + - abi: x86_64 + ndk_target: x86_64-linux-android21 + goarch: amd64 + - abi: x86 + ndk_target: i686-linux-android21 + goarch: 386 steps: - name: Checkout code @@ -115,7 +131,13 @@ jobs: - name: Build libhysteria2 if: steps.cache-libhysteria2-restore.outputs.cache-hit != 'true' run: | - bash libhysteria2.sh + cd hysteria + echo "Building for ${{ matrix.abi }} with ${{ matrix.ndk_target }} (${{ matrix.goarch }})" + CC="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/${{ matrix.ndk_target }}-clang" \ + CGO_ENABLED=1 \ + CGO_LDFLAGS="-Wl,-z,max-page-size=16384" \ + GOOS=android GOARCH=${{ matrix.goarch }} \ + go build -o libs/${{ matrix.abi }}/libhysteria2.so -trimpath -ldflags "-s -w -buildid=" -buildvcs=false ./app env: ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} @@ -134,38 +156,147 @@ jobs: run: | cd ${{ github.workspace }}/V2rayNG chmod 755 gradlew - ./gradlew assembleFdroidRelease -PABI_FILTERS=arm64-v8a - ./gradlew assembleFdroidRelease -PABI_FILTERS=armeabi-v7a - ./gradlew assembleFdroidRelease -PABI_FILTERS=x86_64 - ./gradlew assembleFdroidRelease -PABI_FILTERS=x86 - ./gradlew assembleFdroidRelease + ./gradlew assembleFdroidRelease -PABI_FILTERS=${{ matrix.abi }} env: ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} - - name: Upload arm64-v8a APK + - name: Upload APK uses: actions/upload-artifact@v4 - if: ${{ success() }} + if: ${{ success() }} with: - name: arm64-v8a - path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/*/release/*arm64-v8a*.apk + name: ${{ matrix.abi }} + path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/*/release/*${{ matrix.abi }}*.apk - - name: Upload armeabi-v7a APK - uses: actions/upload-artifact@v4 - if: ${{ success() }} + build-universal: + needs: build + runs-on: ubuntu-latest + if: github.event.inputs.release_tag != '' + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: 'recursive' + fetch-depth: '0' + + - name: Setup Java + uses: actions/setup-java@v4 with: - name: armeabi-v7a - path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/*/release/*armeabi-v7a*.apk + distribution: 'temurin' + java-version: '21' - - name: Upload x86 APK - uses: actions/upload-artifact@v4 - if: ${{ success() }} + - name: Setup Android environment + uses: android-actions/setup-android@v3 + + - name: Restore cached libtun2socks + id: cache-libtun2socks-restore + uses: actions/cache/restore@v4 + with: + path: ${{ github.workspace }}/AndroidLibXrayLite/libs + key: libtun2socks-${{ runner.os }}-${{ hashFiles('.git/modules/AndroidLibXrayLite/modules/badvpn/HEAD') }}-${{ hashFiles('.git/modules/AndroidLibXrayLite/modules/libancillary/HEAD') }} + + - name: Setup Android NDK + uses: nttld/setup-ndk@v1 + id: setup-ndk + # Same version as https://gitlab.com/fdroid/fdroiddata/metadata/com.v2ray.ang.yml + with: + ndk-version: r27 + add-to-path: true + link-to-sdk: true + local-cache: true + + - name: Restore Android Symlinks + run: | + directory="${{ steps.setup-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin" + find "$directory" -type l | while read link; do + current_target=$(readlink "$link") + new_target="$directory/$(basename "$current_target")" + ln -sf "$new_target" "$link" + echo "Changed $(basename "$link") from $current_target to $new_target" + done + + - name: Build libtun2socks + if: steps.cache-libtun2socks-restore.outputs.cache-hit != 'true' + run: | + cd ${{ github.workspace }}/AndroidLibXrayLite + bash compile-tun2socks.sh + tar -xvzf libtun2socks.so.tgz + env: + NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} + + - name: Save libtun2socks + if: steps.cache-libtun2socks-restore.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: ${{ github.workspace }}/AndroidLibXrayLite/libs + key: libtun2socks-${{ runner.os }}-${{ hashFiles('.git/modules/AndroidLibXrayLite/modules/badvpn/HEAD') }}-${{ hashFiles('.git/modules/AndroidLibXrayLite/modules/libancillary/HEAD') }} + + - name: Copy libtun2socks + run: | + cp -r ${{ github.workspace }}/AndroidLibXrayLite/libs ${{ github.workspace }}/V2rayNG/app + + - name: Fetch AndroidLibXrayLite tag + run: | + pushd AndroidLibXrayLite + CURRENT_TAG=$(git describe --tags --abbrev=0) + echo "Current tag in this repo: $CURRENT_TAG" + echo "CURRENT_TAG=$CURRENT_TAG" >> $GITHUB_ENV + popd + + - name: Download libv2ray + uses: robinraju/release-downloader@v1 with: - name: x86-apk - path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/*/release/*x86*.apk + repository: '2dust/AndroidLibXrayLite' + tag: ${{ env.CURRENT_TAG }} + 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('libhysteria2.sh') }} + + - name: Setup Golang + if: steps.cache-libhysteria2-restore.outputs.cache-hit != 'true' + uses: actions/setup-go@v5 + with: + go-mod-file: 'AndroidLibXrayLite/go.mod' + + - name: Patch Go use 600296 + #https://go-review.googlesource.com/c/go/+/600296 + run: | + cd "$(go env GOROOT)" + curl "https://go-review.googlesource.com/changes/go~600296/revisions/5/patch" | base64 -d | patch --verbose -p 1 + + - 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('libhysteria2.sh') }} + + - name: Copy libhysteria2 + run: | + cp -r ${{ github.workspace }}/hysteria/libs ${{ github.workspace }}/V2rayNG/app + + - name: Build Universal APK + run: | + cd ${{ github.workspace }}/V2rayNG + chmod 755 gradlew + ./gradlew assembleFdroidRelease -PABI_FILTERS=arm64-v8a;armeabi-v7a;x86_64;x86 + env: + ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} - - name: Upload to release + - name: Upload Universal APK to Release uses: svenstaro/upload-release-action@v2 - if: github.event.inputs.release_tag != '' with: file: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/*fdroid*/release/*.apk tag: ${{ github.event.inputs.release_tag }} diff --git a/V2rayNG/app/build.gradle.kts b/V2rayNG/app/build.gradle.kts index 8e6d9aad9..c9dbc7c60 100644 --- a/V2rayNG/app/build.gradle.kts +++ b/V2rayNG/app/build.gradle.kts @@ -23,6 +23,7 @@ android { isEnable = true reset() include(*abiFilterList.toTypedArray()) + isUniversalApk = true } } }