Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 96 additions & 48 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
workflow_dispatch:
inputs:
release_tag:
required: false
type: string
pull_request:
branches:
Expand All @@ -13,59 +12,108 @@ on:
branches:
- main

permissions:
contents: read

defaults:
run:
shell: bash

jobs:
build:
name: Build Android bindings
runs-on: ubuntu-latest
steps:
- name: Check out source
uses: actions/checkout@v7
with:
persist-credentials: false

- name: Set up Java
uses: actions/setup-java@v6
with:
distribution: temurin
java-version: latest

- name: Set up Go
uses: actions/setup-go@v7
with:
go-version: stable
check-latest: true

- name: Install Gomobile and Gobind
run: |
go get golang.org/x/mobile@latest
go mod tidy
mobile_version=$(go list -m -f '{{.Version}}' golang.org/x/mobile)
go install "golang.org/x/mobile/cmd/gomobile@$mobile_version" \
"golang.org/x/mobile/cmd/gobind@$mobile_version"

- name: Checkout repository
uses: actions/checkout@v6

- name: Setup Golang
uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- name: Install Android CLI
run: |
cli_dir="$RUNNER_TEMP/android-cli"
mkdir -p "$cli_dir"
curl --fail --silent --show-error --location --retry 3 \
https://dl.google.com/android/cli/latest/linux_x86_64/android \
--output "$cli_dir/android"
chmod +x "$cli_dir/android"
"$cli_dir/android" --version
echo "$cli_dir" >> "$GITHUB_PATH"

- name: Install gomobile
run: |
go install golang.org/x/mobile/cmd/gomobile@latest
export PATH=$PATH:~/go/bin

- name: Setup Android SDK
uses: android-actions/setup-android@v4
with:
log-accepted-android-sdk-licenses: false
cmdline-tools-version: '14742923'
packages: 'platforms;android-37.0 build-tools;37.0.0 platform-tools'
- name: Install stable Android platform and NDK
run: |
sdk_dir="$RUNNER_TEMP/android-sdk"
mkdir -p "$sdk_dir"
packages=$(android --sdk="$sdk_dir" sdk list --all)
latest_package() {
awk -v pattern="$1" '$1 ~ pattern && $2 ~ /^[0-9]+([.][0-9]+)*$/ { print $1 }' <<< "$packages" | sort -V | tail -n1
}
ndk=$(latest_package '^ndk/[0-9]+[.][0-9]+[.][0-9]+$')
platform=$(latest_package '^platforms/android-[0-9]+([.][0-9]+)?$')
if [[ -z "$ndk" || -z "$platform" ]]; then
echo "::error::Could not resolve a stable Android platform and NDK"
exit 1
fi
printf 'Android SDK packages: %s %s\n' "$ndk" "$platform"
android --sdk="$sdk_dir" sdk install "$ndk" "$platform"
echo "ANDROID_HOME=$sdk_dir" >> "$GITHUB_ENV"

- name: Install NDK
run: |
echo "y" | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager \
--channel=0 \
--install "ndk;29.0.14206865"
echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/29.0.14206865" >> $GITHUB_ENV
- name: Prepare Geo assets
run: |
bash gen_assets.sh download
mkdir -p assets
cp data/geoip.dat data/geosite.dat data/geoip-only-cn-private.dat assets/

- name: Build
run: |
mkdir -p assets data
bash gen_assets.sh download
cp -v data/*.dat assets/
gomobile init
go mod tidy
gomobile bind -v -androidapi 24 -trimpath -ldflags='-s -w -buildid= -checklinkname=0' ./

- name: Upload build artifacts
if: github.event.inputs.release_tag == ''
uses: actions/upload-artifact@v7
with:
name: libv2ray
path: |
${{ github.workspace }}/libv2ray*r
- name: Build Android bindings
env:
JDK_JAVAC_OPTIONS: -Xlint:-options
run: gomobile bind -v -androidapi 24 -trimpath -ldflags='-s -w -buildid= -checklinkname=0' ./

- name: Upload build artifacts
uses: actions/upload-artifact@v7
with:
name: libv2ray
path: |
libv2ray.aar
libv2ray-sources.jar
if-no-files-found: error

release:
name: Publish release
needs: build
if: github.event_name == 'workflow_dispatch' && inputs.release_tag != ''
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@v8
with:
name: libv2ray

- name: Upload AndroidLibXrayLite to release
if: github.event.inputs.release_tag != ''
uses: svenstaro/upload-release-action@v2
with:
file: ./libv2ray*r
tag: ${{ github.event.inputs.release_tag }}
file_glob: true
- name: Publish release assets
uses: svenstaro/upload-release-action@v2
with:
file: libv2ray*r
tag: ${{ inputs.release_tag }}
file_glob: true
117 changes: 47 additions & 70 deletions .github/workflows/tidy.yml
Original file line number Diff line number Diff line change
@@ -1,98 +1,75 @@
name: Check and Update xray-core
name: Update Xray-core

on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

permissions:
contents: write
actions: write

defaults:
run:
shell: bash

jobs:
update:
name: Update Go dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout our repository
uses: actions/checkout@v5
- name: Check out source
uses: actions/checkout@v7
with:
fetch-depth: '0'

- name: Fetch latest release tag from external repository
id: fetch-release
run: |
EXTERNAL_REPO="XTLS/Xray-core"
LATEST_TAG=$(curl -s https://api.github.com/repos/$EXTERNAL_REPO/tags | jq -r '.[0]')
LATEST_TAG_NAME=$(echo $LATEST_TAG | jq -r .name)
LATEST_TAG_SHA=$(echo $LATEST_TAG | jq -r .commit.sha)
echo "Latest tag from external repo: $LATEST_TAG_NAME"
echo "LATEST_TAG_NAME=$LATEST_TAG_NAME" >> $GITHUB_ENV
echo "LATEST_TAG_SHA=$LATEST_TAG_SHA" >> $GITHUB_ENV
fetch-depth: 0

- name: Fetch current repository release tag
id: fetch-current-tag
- name: Resolve latest Xray-core tag
run: |
CURRENT_TAG_NAME=$(git describe --tags --abbrev=0)
echo "Current tag in this repo: $CURRENT_TAG_NAME"
echo "CURRENT_TAG_NAME=$CURRENT_TAG_NAME" >> $GITHUB_ENV
refs=$(git ls-remote --tags --sort=-version:refname https://github.com/XTLS/Xray-core.git 'refs/tags/v*')
tag=$(awk '$2 ~ /^refs\/tags\/v[0-9]+\.[0-9]+\.[0-9]+$/ && !tag { tag = $2 } END { print tag }' <<< "$refs")
[[ -n "$tag" ]]
sha=$(awk -v tag="$tag" '$2 == tag { sha = $1 } $2 == tag "^{}" { peeled = $1 } END { print peeled ? peeled : sha }' <<< "$refs")
[[ "$sha" =~ ^[0-9a-f]{40}$ ]]
{
echo "LATEST_TAG_NAME=${tag#refs/tags/}"
echo "LATEST_TAG_SHA=$sha"
} >> "$GITHUB_ENV"

- name: Compare tags
id: compare-tags
- name: Compare Xray-core tags
run: |
if [ "$LATEST_TAG_NAME" != "$CURRENT_TAG_NAME" ]; then
if [ "$(printf '%s\n' "$LATEST_TAG_NAME" "$CURRENT_TAG_NAME" | sort -V | tail -n1)" == "$CURRENT_TAG_NAME" ]; then
echo "Upstream LATEST_TAG_NAME less than the CURRENT_TAG_NAME, no update needed."
else
echo "Tags are different. Updating..."
echo "needs_update=true" >> $GITHUB_ENV
fi
else
echo "Tags are the same. No update needed."
echo "needs_update=false" >> $GITHUB_ENV
current_tag=$(git describe --tags --abbrev=0)
newest_tag=$(printf '%s\n' "$current_tag" "$LATEST_TAG_NAME" | sort -V | tail -n1)
if [[ "$LATEST_TAG_NAME" != "$current_tag" && "$LATEST_TAG_NAME" == "$newest_tag" ]]; then
echo "needs_update=true" >> "$GITHUB_ENV"
fi

- name: Setup Golang
- name: Set up Go
if: env.needs_update == 'true'
uses: actions/setup-go@v5.4.0
uses: actions/setup-go@v7
with:
go-version: 'stable'
go-version: stable
check-latest: true

- name: Update and commit changes
- name: Update Go dependencies
if: env.needs_update == 'true'
run: |
# Sync Go version from upstream go.mod
EXTERNAL_REPO="XTLS/Xray-core"
GO_VERSION=$(curl -s https://raw.githubusercontent.com/$EXTERNAL_REPO/${{ env.LATEST_TAG_NAME }}/go.mod | awk '/^go / {print $2; exit}')
if [ -n "$GO_VERSION" ]; then
echo "Syncing Go version to $GO_VERSION"
go mod edit -go=$GO_VERSION
else
echo "Failed to detect Go version from upstream go.mod"
fi

go get github.com/xtls/xray-core@${{ env.LATEST_TAG_SHA }}
go get golang.org/x/mobile@latest

# Clean up and verify module dependencies
go mod tidy -v

# Show changes
git diff
go_version=$(curl -fsSL "https://raw.githubusercontent.com/XTLS/Xray-core/$LATEST_TAG_SHA/go.mod" | awk '$1 == "go" { print $2 }')
[[ "$go_version" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]
go mod edit -go="$go_version"
go get "github.com/xtls/xray-core@$LATEST_TAG_SHA" golang.org/x/mobile@latest
go mod tidy

- name: Commit and push changes
id: auto-commit-action
id: commit
if: env.needs_update == 'true'
uses: stefanzweifel/git-auto-commit-action@v5.1.0
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: Updating xray-core to ${{ env.LATEST_TAG_NAME }} ${{ env.LATEST_TAG_SHA }}
tagging_message: ${{ env.LATEST_TAG_NAME }}
file_pattern: go.mod go.sum
tag_name: ${{ env.LATEST_TAG_NAME }}

- name: Trigger build
if: env.needs_update == 'true' && steps.auto-commit-action.outputs.changes_detected == 'true'
run: |
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/main.yml/dispatches \
-d "{
\"ref\": \"main\",
\"inputs\": {
\"release_tag\": \"${{ env.LATEST_TAG_NAME }}\"
}
}"
- name: Dispatch release build
if: env.needs_update == 'true' && steps.commit.outputs.changes_detected == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: gh workflow run main.yml --repo "$GITHUB_REPOSITORY" --ref "$LATEST_TAG_NAME" -f "release_tag=$LATEST_TAG_NAME"
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
# AndroidLibXrayLite

## Build requirements
* JDK
* Latest stable Temurin JDK
* Android SDK
* Go
* gomobile

## Build instructions
1. `git clone [repo] && cd AndroidLibXrayLite`
2. `gomobile init`
3. `go mod tidy -v`
4. `gomobile bind -v -androidapi 24 -trimpath -ldflags='-s -w -buildid= -checklinkname=0' ./`
Run from the repository root with the SDK and NDK from the build workflow.
Set `JAVA_HOME` and put `$JAVA_HOME/bin` on `PATH`.

```sh
go get golang.org/x/mobile@latest
go mod tidy
export GOBIN="$(go env GOPATH)/bin"
export PATH="$GOBIN:$PATH"
mobile_version="$(go list -m -f '{{.Version}}' golang.org/x/mobile)"
go install "golang.org/x/mobile/cmd/gomobile@$mobile_version" \
"golang.org/x/mobile/cmd/gobind@$mobile_version"

bash gen_assets.sh download
mkdir -p assets
cp data/geoip.dat data/geosite.dat data/geoip-only-cn-private.dat assets/
JDK_JAVAC_OPTIONS=-Xlint:-options gomobile bind -v -androidapi 24 -trimpath -ldflags='-s -w -buildid= -checklinkname=0' ./
```

Gomobile targets Java 8. The javac flag suppresses obsolete-option warnings for
this build. The linker flag lets anet resolve named IPv6 zones on Android.
Loading