Skip to content

Commit

Permalink
Sagernet (#4194)
Browse files Browse the repository at this point in the history
* switch to sagernet/gomobile

* arguments for rb

* match ndk version

* with more options

* nttld/setup-ndk#518
  • Loading branch information
UjuiUjuMandan authored and UntuKemeng committed Mar 3, 2025
1 parent d34d84b commit a69c14a
Showing 1 changed file with 175 additions and 159 deletions.
334 changes: 175 additions & 159 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,162 +18,178 @@ jobs:
permissions: write-all

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Prepare build dir
run: |
mkdir ${{ github.workspace }}/build
- name: Fetch AndroidLibV2rayLite
run: |
cd ${{ github.workspace }}/build
git clone --depth=1 -b master https://github.com/2dust/AndroidLibV2rayLite.git
cd AndroidLibV2rayLite
git submodule update --init
- name: Restore cached libtun2socks
id: cache-libtun2socks-restore
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/build/AndroidLibV2rayLite/libs
key: libtun2socks-${{ runner.os }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/refs/heads/master') }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/modules/badvpn/HEAD') }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/modules/libancillary/HEAD') }}

- name: Setup Android NDK
if: steps.cache-libtun2socks-restore.outputs.cache-hit != 'true'
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

- name: Build libtun2socks
if: steps.cache-libtun2socks-restore.outputs.cache-hit != 'true'
run: |
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 }}

- name: Save libtun2socks
if: steps.cache-libtun2socks-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}/build/AndroidLibV2rayLite/libs
key: libtun2socks-${{ runner.os }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/refs/heads/master') }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/modules/badvpn/HEAD') }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/modules/libancillary/HEAD') }}

- name: Copy libtun2socks
run: |
cp -r ${{ github.workspace }}/build/AndroidLibV2rayLite/libs/* ${{ github.workspace }}/V2rayNG/app/libs/
- name: Fetch AndroidLibXrayLite
run: |
cd ${{ github.workspace }}/build
git clone --depth=1 -b main https://github.com/2dust/AndroidLibXrayLite.git
- name: Restore cached libv2ray
id: cache-libv2ray-restore
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/build/AndroidLibXrayLite/
key: libv2ray-${{ runner.os }}-${{ hashFiles('build/AndroidLibXrayLite/.git/refs/heads/main') }}

- name: Setup Golang
if: steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
uses: actions/setup-go@v5
with:
go-version: '1.23.4'
cache: false

- name: Patch Go use 600296
if: steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
#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: Install gomobile
if: steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
run: |
go install golang.org/x/mobile/cmd/gomobile@v0.0.0-20240806205939-81131f6468ab
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Build libv2ray
if: steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/build/AndroidLibXrayLite
gomobile init
go mod tidy -v
gomobile bind -v -androidapi 27 -ldflags='-s -w' ./
- name: Save libv2ray
if: steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}/build/AndroidLibXrayLite/
key: libv2ray-${{ runner.os }}-${{ hashFiles('build/AndroidLibXrayLite/.git/refs/heads/main') }}

- name: Copy libv2ray
run: |
cp -r ${{ github.workspace }}/build/AndroidLibXrayLite/*.aar ${{ github.workspace }}/V2rayNG/app/libs/
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'

- name: Setup Android environment
uses: android-actions/setup-android@v3

- name: Build
run: |
cd ${{ github.workspace }}/V2rayNG
chmod 755 gradlew
./gradlew assemble
- name: arm64
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: Arm64
path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/release/*arm64-v8a.apk

- name: armeabi-v7a
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: Armeabi-v7a
path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/release/*armeabi-v7a.apk

- name: x86
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: X86
path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/release/*x86.apk

- name: x86_64
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: X86_64
path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/release/*x86_64.apk

- name: universal
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: Universal
path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/release/*universal.apk

- name: Upload to release
uses: svenstaro/upload-release-action@v2
if: github.event.inputs.release_tag != ''
with:
file: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/*playstore*/release/*.apk
tag: ${{ github.event.inputs.release_tag }}
file_glob: true
prerelease: true
- name: Checkout
uses: actions/checkout@v4

- name: Prepare build dir
run: |
mkdir ${{ github.workspace }}/build
- name: Fetch AndroidLibV2rayLite
run: |
cd ${{ github.workspace }}/build
git clone --depth=1 -b master https://github.com/2dust/AndroidLibV2rayLite.git
cd AndroidLibV2rayLite
git submodule update --init
- name: Restore cached libtun2socks
id: cache-libtun2socks-restore
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/build/AndroidLibV2rayLite/libs
key: libtun2socks-${{ runner.os }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/refs/heads/master') }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/modules/badvpn/HEAD') }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/modules/libancillary/HEAD') }}

- name: Fetch AndroidLibXrayLite
run: |
cd ${{ github.workspace }}/build
git clone --depth=1 -b main https://github.com/2dust/AndroidLibXrayLite.git
- name: Restore cached libv2ray
id: cache-libv2ray-restore
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/build/AndroidLibXrayLite/
key: libv2ray-${{ runner.os }}-${{ hashFiles('build/AndroidLibXrayLite/.git/refs/heads/main') }}

- name: Setup Android NDK
if: steps.cache-libtun2socks-restore.outputs.cache-hit != 'true' || steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
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
if: steps.cache-libtun2socks-restore.outputs.cache-hit != 'true' || steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
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 }}/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 }}

- name: Save libtun2socks
if: steps.cache-libtun2socks-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}/build/AndroidLibV2rayLite/libs
key: libtun2socks-${{ runner.os }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/refs/heads/master') }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/modules/badvpn/HEAD') }}-${{ hashFiles('build/AndroidLibV2rayLite/.git/modules/libancillary/HEAD') }}

- name: Copy libtun2socks
run: |
cp -r ${{ github.workspace }}/build/AndroidLibV2rayLite/libs/* ${{ github.workspace }}/V2rayNG/app/libs/
- name: Setup Golang
if: steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
uses: actions/setup-go@v5
with:
go-version: '1.23.4'
cache: false

- name: Patch Go use 600296
if: steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
#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: Install gomobile
if: steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
run: |
CGO_ENABLED=0 go install -trimpath -ldflags="-w -s" github.com/sagernet/gomobile/cmd/gomobile@v0.1.4
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
- name: Build libv2ray
if: steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}/build/AndroidLibXrayLite
gomobile init
go mod tidy -v
gomobile bind -trimpath -buildvcs=false -v -androidapi 21 -ldflags='-s -w -buildid=' ./
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}

- name: Save libv2ray
if: steps.cache-libv2ray-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}/build/AndroidLibXrayLite/
key: libv2ray-${{ runner.os }}-${{ hashFiles('build/AndroidLibXrayLite/.git/refs/heads/main') }}

- name: Copy libv2ray
run: |
cp -r ${{ github.workspace }}/build/AndroidLibXrayLite/*.aar ${{ github.workspace }}/V2rayNG/app/libs/
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'

- name: Setup Android environment
uses: android-actions/setup-android@v3

- name: Build
run: |
cd ${{ github.workspace }}/V2rayNG
chmod 755 gradlew
./gradlew assemble
- name: arm64
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: Arm64
path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/release/*arm64-v8a.apk

- name: armeabi-v7a
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: Armeabi-v7a
path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/release/*armeabi-v7a.apk

- name: x86
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: X86
path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/release/*x86.apk

- name: x86_64
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: X86_64
path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/release/*x86_64.apk

- name: universal
uses: actions/upload-artifact@v4
if: ${{ success() }}
with:
name: Universal
path: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/release/*universal.apk

- name: Upload to release
uses: svenstaro/upload-release-action@v2
if: github.event.inputs.release_tag != ''
with:
file: ${{ github.workspace }}/V2rayNG/app/build/outputs/apk/*playstore*/release/*.apk
tag: ${{ github.event.inputs.release_tag }}
file_glob: true
prerelease: true

0 comments on commit a69c14a

Please sign in to comment.