system lays them out download-sdk.sh unpacks the SDK as buildscripts/sdk/android-sdk-linux, and mpv-android keeps the libraries in app/src/main/libs with jniLibs pointing at it. Check those names first, fall back to a platforms/ search, and write the libraries into libs/<abi> while recreating the alias.
293 lines
12 KiB
YAML
293 lines
12 KiB
YAML
|
|
name: build-android
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
mpv_ref:
|
|
description: "Upstream mpv branch, tag or commit"
|
|
required: false
|
|
default: "master"
|
|
push:
|
|
branches: [main]
|
|
tags: ["v*"]
|
|
|
|
jobs:
|
|
arm64:
|
|
runs-on: ubuntu-24.04
|
|
timeout-minutes: 300
|
|
env:
|
|
MPV_REF: ${{ inputs.mpv_ref || 'master' }}
|
|
|
|
steps:
|
|
- name: Checkout mpv-joc
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Checkout mpv-android build system
|
|
run: git clone --depth 1 https://github.com/mpv-android/mpv-android.git android
|
|
|
|
- name: Set up Java
|
|
uses: actions/setup-java@v4
|
|
with:
|
|
distribution: temurin
|
|
java-version: '17'
|
|
|
|
- name: Install host build tools
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y \
|
|
autoconf automake libtool pkg-config ninja-build gperf nasm yasm \
|
|
python3-pip cmake gettext autopoint unzip xz-utils bzip2 wget
|
|
python3 -m pip install --user --break-system-packages --upgrade meson
|
|
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
|
|
|
- name: Download Android SDK and NDK
|
|
working-directory: android/buildscripts
|
|
env:
|
|
IN_CI: '1'
|
|
run: ./include/download-sdk.sh
|
|
|
|
- name: Clone JOC core
|
|
run: git clone --depth 1 https://github.com/TheM14/JustOneCacophony.git joc
|
|
|
|
- name: Build libjoc_core.so for arm64-v8a
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
source android/buildscripts/include/depinfo.sh
|
|
ndk="$GITHUB_WORKSPACE/android/buildscripts/sdk/android-ndk-${v_ndk}"
|
|
test -f "$ndk/build/cmake/android.toolchain.cmake"
|
|
cmake -S joc -B joc/build-android -G Ninja \
|
|
-DCMAKE_TOOLCHAIN_FILE="$ndk/build/cmake/android.toolchain.cmake" \
|
|
-DANDROID_ABI=arm64-v8a \
|
|
-DANDROID_PLATFORM=android-23 \
|
|
-DANDROID_STL=c++_shared \
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
-DJOC_BUILD_TESTS=OFF \
|
|
-DJOC_BUILD_DEVTOOLS=OFF
|
|
cmake --build joc/build-android --target joc_core --parallel 4
|
|
test -s joc/build-android/libjoc_core.so
|
|
|
|
- name: Checkout upstream mpv and apply JOC patch
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
mpv_dir=android/buildscripts/deps/mpv
|
|
mkdir -p "$mpv_dir"
|
|
git -C "$mpv_dir" init -q
|
|
git -C "$mpv_dir" remote add origin https://github.com/mpv-player/mpv.git
|
|
git -C "$mpv_dir" fetch --depth 1 origin "$MPV_REF"
|
|
git -C "$mpv_dir" checkout --detach FETCH_HEAD
|
|
git -C "$mpv_dir" log -1 --format='%h %cd %s' --date=short
|
|
cp fork/files/audio/decode/* "$mpv_dir/audio/decode/"
|
|
python3 fork/tools/apply_edits.py "$mpv_dir"
|
|
|
|
- name: Restore Android native dependencies
|
|
id: dep-cache
|
|
uses: actions/cache/restore@v4
|
|
with:
|
|
path: android/buildscripts/prefix/arm64
|
|
key: android-arm64-deps-${{ hashFiles('android/buildscripts/include/depinfo.sh') }}-v1
|
|
|
|
- name: Download native dependency sources
|
|
if: steps.dep-cache.outputs.cache-hit != 'true'
|
|
working-directory: android/buildscripts
|
|
env:
|
|
IN_CI: '1'
|
|
run: ./include/download-deps.sh
|
|
|
|
- name: Compile native dependencies (arm64 only)
|
|
if: steps.dep-cache.outputs.cache-hit != 'true'
|
|
working-directory: android/buildscripts
|
|
run: ./buildall.sh --arch arm64 --only-deps mpv
|
|
|
|
- name: Cache native dependencies
|
|
if: steps.dep-cache.outputs.cache-hit != 'true'
|
|
uses: actions/cache/save@v4
|
|
with:
|
|
path: android/buildscripts/prefix/arm64
|
|
key: android-arm64-deps-${{ hashFiles('android/buildscripts/include/depinfo.sh') }}-v1
|
|
|
|
- name: Install JOC core into Android prefix
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
cp joc/build-android/libjoc_core.so android/buildscripts/prefix/arm64/lib/
|
|
|
|
- name: Enable JOC linking in mpv-android build script
|
|
run: |
|
|
python3 - <<'PY'
|
|
from pathlib import Path
|
|
p = Path('android/buildscripts/scripts/mpv.sh')
|
|
s = p.read_text()
|
|
needle = '-Dmanpage-build=disabled'
|
|
if s.count(needle) != 1:
|
|
raise SystemExit('mpv-android build script has changed; adjust the Meson arguments')
|
|
s = s.replace(needle, needle + ' -Dgpl=false -Djoc-core-dir="$prefix_dir/lib"')
|
|
p.write_text(s)
|
|
PY
|
|
|
|
- name: Build Android libmpv.so
|
|
working-directory: android/buildscripts
|
|
run: ./buildall.sh --arch arm64 -n mpv
|
|
|
|
- name: Package Android shared libraries
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
source android/buildscripts/include/depinfo.sh
|
|
ndk="$GITHUB_WORKSPACE/android/buildscripts/sdk/android-ndk-${v_ndk}"
|
|
out=dist/arm64-v8a
|
|
mkdir -p "$out"
|
|
cp android/buildscripts/prefix/arm64/lib/libmpv.so "$out/"
|
|
cp joc/build-android/libjoc_core.so "$out/"
|
|
libcxx=$(find "$ndk/toolchains/llvm/prebuilt" \
|
|
-path '*/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so' -print -quit)
|
|
test -n "$libcxx"
|
|
cp "$libcxx" "$out/"
|
|
test -s "$out/libmpv.so"
|
|
test -s "$out/libjoc_core.so"
|
|
readelf -h "$out/libmpv.so" | grep Machine
|
|
readelf -d "$out/libmpv.so" | grep NEEDED
|
|
readelf -d "$out/libmpv.so" | grep -F libjoc_core.so
|
|
readelf -d "$out/libjoc_core.so" | grep NEEDED
|
|
ls -lh "$out"
|
|
|
|
- name: Upload compiled Android libraries
|
|
if: success()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: mpv-ad-joc-android-arm64-v8a
|
|
path: dist/arm64-v8a/
|
|
if-no-files-found: error
|
|
|
|
- name: Install the native libraries into the app
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
abi=arm64-v8a
|
|
main="$GITHUB_WORKSPACE/android/app/src/main"
|
|
# mpv-android keeps the libraries in src/main/libs and points jniLibs
|
|
# at it with a relative symlink; the link dangles until that directory
|
|
# exists, so write into libs and keep the alias intact.
|
|
if [ -L "$main/jniLibs" ]; then
|
|
echo "jniLibs is a symlink to $(readlink "$main/jniLibs" 2>/dev/null || echo '?')"
|
|
rm -f "$main/jniLibs"
|
|
elif [ -e "$main/jniLibs" ] && [ ! -d "$main/jniLibs" ]; then
|
|
echo "jniLibs is a file; moving it aside"
|
|
rm -f "$main/jniLibs"
|
|
fi
|
|
libs="$main/libs/$abi"
|
|
mkdir -p "$libs"
|
|
cp "$GITHUB_WORKSPACE/android/buildscripts/prefix/arm64/lib/libmpv.so" "$libs/"
|
|
cp "$GITHUB_WORKSPACE/joc/build-android/libjoc_core.so" "$libs/"
|
|
source "$GITHUB_WORKSPACE/android/buildscripts/include/depinfo.sh"
|
|
libcxx=$(find "$GITHUB_WORKSPACE/android/buildscripts/sdk/android-ndk-${v_ndk}/toolchains/llvm/prebuilt" \
|
|
-path '*/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so' -print -quit)
|
|
test -n "$libcxx"
|
|
cp "$libcxx" "$libs/"
|
|
if [ ! -e "$main/jniLibs" ]; then
|
|
ln -s libs "$main/jniLibs"
|
|
fi
|
|
ls -lh "$libs"
|
|
|
|
- name: Cache the Gradle home
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
~/.gradle/caches
|
|
~/.gradle/wrapper
|
|
key: gradle-${{ runner.os }}-${{ hashFiles('android/**/*.gradle', 'android/**/*.gradle.kts', 'android/gradle/wrapper/gradle-wrapper.properties') }}
|
|
|
|
- name: Build the Android APK
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
# download-sdk.sh unpacks the SDK under android/buildscripts/sdk; find
|
|
# the root from its platforms/ directory instead of hard-coding the
|
|
# layout (the current one is sdk/android-sdk-linux).
|
|
sdk_dir=""
|
|
for candidate in \
|
|
"$GITHUB_WORKSPACE/android/buildscripts/sdk/android-sdk-linux" \
|
|
"$GITHUB_WORKSPACE/android/buildscripts/sdk/android-sdk" \
|
|
"$GITHUB_WORKSPACE/android/buildscripts/sdk"; do
|
|
if [ -d "$candidate/platforms" ]; then sdk_dir="$candidate"; break; fi
|
|
done
|
|
if [ -z "$sdk_dir" ]; then
|
|
platforms=$(find "$GITHUB_WORKSPACE/android/buildscripts/sdk" \
|
|
-maxdepth 2 -type d -name platforms -print -quit 2>/dev/null || true)
|
|
if [ -n "$platforms" ]; then sdk_dir=$(dirname "$platforms"); fi
|
|
fi
|
|
if [ -z "$sdk_dir" ]; then
|
|
echo "::error::no Android SDK (no platforms/ directory) under android/buildscripts/sdk"
|
|
find "$GITHUB_WORKSPACE/android/buildscripts/sdk" -maxdepth 3 -type d | head -40
|
|
exit 1
|
|
fi
|
|
echo "Android SDK: $sdk_dir"
|
|
echo "ANDROID_SDK_ROOT=$sdk_dir" >> "$GITHUB_ENV"
|
|
echo "ANDROID_HOME=$sdk_dir" >> "$GITHUB_ENV"
|
|
echo "sdk.dir=$sdk_dir" > "$GITHUB_WORKSPACE/android/local.properties"
|
|
# Accept the SDK licences, so AGP may install whatever compileSdk or
|
|
# build-tools the app asks for instead of failing on an unaccepted hash.
|
|
sdkmanager=$(find "$sdk_dir/cmdline-tools" -maxdepth 3 -type f -name sdkmanager -print -quit 2>/dev/null || true)
|
|
if [ -n "$sdkmanager" ]; then
|
|
yes | "$sdkmanager" --sdk_root="$sdk_dir" --licenses >/dev/null 2>&1 || true
|
|
fi
|
|
# The NDK is unpacked as android-ndk-<release>; AGP looks it up by the
|
|
# source.properties revision under ndk/, so link it there too.
|
|
source "$GITHUB_WORKSPACE/android/buildscripts/include/depinfo.sh"
|
|
ndk="$GITHUB_WORKSPACE/android/buildscripts/sdk/android-ndk-${v_ndk}"
|
|
if [ -d "$ndk" ]; then
|
|
ndk_revision=$(sed -n 's/^Pkg\.Revision *= *//p' "$ndk/source.properties" 2>/dev/null | head -1)
|
|
mkdir -p "$sdk_dir/ndk"
|
|
ln -sfn "$ndk" "$sdk_dir/ndk/${ndk_revision:-$v_ndk}"
|
|
fi
|
|
# A throwaway key keeps the artifact installable; replace it with a
|
|
# repository secret when the build should be signed for distribution.
|
|
keytool -genkeypair -noprompt -keystore "$GITHUB_WORKSPACE/ci-signing.jks" \
|
|
-storepass android -keypass android -alias androiddebugkey \
|
|
-keyalg RSA -keysize 2048 -validity 10000 \
|
|
-dname "CN=mpv-joc CI, O=mpv-joc, C=CN"
|
|
cd "$GITHUB_WORKSPACE/android"
|
|
./gradlew --no-daemon --stacktrace assembleRelease \
|
|
-Pandroid.injected.signing.store.file="$GITHUB_WORKSPACE/ci-signing.jks" \
|
|
-Pandroid.injected.signing.store.password=android \
|
|
-Pandroid.injected.signing.key.alias=androiddebugkey \
|
|
-Pandroid.injected.signing.key.password=android
|
|
|
|
- name: Collect the APK
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
mkdir -p dist/apk
|
|
mapfile -t apks < <(find "$GITHUB_WORKSPACE/android/app/build/outputs/apk" -name '*.apk' -print)
|
|
if [ ${#apks[@]} -eq 0 ]; then
|
|
echo "::error::the Gradle build finished without an APK"
|
|
find "$GITHUB_WORKSPACE/android/app/build/outputs" -maxdepth 4 -type f | head -40
|
|
exit 1
|
|
fi
|
|
apksigner=$(find "$GITHUB_WORKSPACE/android/buildscripts/sdk" -path '*/build-tools/*/apksigner' -type f -print -quit 2>/dev/null || true)
|
|
for apk in "${apks[@]}"; do
|
|
if [ -n "$apksigner" ]; then
|
|
"$apksigner" verify --print-certs "$apk" | head -2
|
|
fi
|
|
done
|
|
cp "${apks[@]}" dist/apk/
|
|
ls -lh dist/apk
|
|
|
|
- name: Upload the Android APK
|
|
if: success()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: mpv-joc-android-arm64-v8a-apk
|
|
path: dist/apk/
|
|
if-no-files-found: error
|
|
|
|
- name: Upload JOC core even if mpv fails
|
|
if: failure()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: android-joc-core-debug
|
|
path: joc/build-android/libjoc_core.so
|
|
if-no-files-found: ignore
|