The app's MPVLib loads libplayer.so before libmpv, and mpv-android builds that bridge with ndk-build over app/src/main/jni, installing it and the prebuilt ffmpeg/mpv objects into app/src/main/libs/<abi>. The workflow only built the mpv target and then ran Gradle, so the APK shipped without libplayer.so and every playback died with UnsatisfiedLinkError. Run ndk-build the way buildscripts/scripts/mpv-android.sh does, and write ndk.properties, which the Gradle build needs to find the NDK for symbol stripping (the previous APK carried 134 MB of unstripped libraries).
363 lines
16 KiB
YAML
363 lines
16 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: Build the JNI bridge (libplayer.so)
|
|
shell: bash
|
|
run: |
|
|
set -euo pipefail
|
|
cd "$GITHUB_WORKSPACE/android"
|
|
source buildscripts/include/path.sh
|
|
source buildscripts/include/depinfo.sh
|
|
ndk="$GITHUB_WORKSPACE/android/buildscripts/sdk/android-ndk-${v_ndk}"
|
|
export ANDROID_NDK_ROOT="$ndk"
|
|
export PATH="$ndk:$PATH"
|
|
# mpv-android's own build runs ndk-build over app/src/main/jni and
|
|
# installs libplayer.so plus the prebuilt ffmpeg/mpv objects into
|
|
# app/src/main/libs/<abi>, which is what the jniLibs symlink points
|
|
# at. The app loads libplayer.so before libmpv, so without this step
|
|
# every playback dies with UnsatisfiedLinkError.
|
|
PREFIX32="" PREFIX64="$(realpath buildscripts/prefix/arm64)" \
|
|
PREFIX_X86="" PREFIX_X64="" \
|
|
ndk-build -C app/src/main -j"$(nproc)"
|
|
# The Gradle build reads this to find the NDK for symbol stripping.
|
|
printf '%s\n' \
|
|
"# This file is automatically written by the build scripts, and read using Gradle" \
|
|
"ndkVersion=$v_ndk_n" "ndkRoot=$ANDROID_NDK_ROOT" > ndk.properties
|
|
ls -l app/src/main/libs/arm64-v8a
|
|
|
|
- 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/*.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"
|
|
echo "staged by the build scripts in libs/$abi:"
|
|
ls -l "$libs" 2>/dev/null || true
|
|
# This build links the ffmpeg stack dynamically, so the app needs
|
|
# every shared object from the cross-build prefix, not just libmpv.so
|
|
# (libmpv's DT_NEEDED lists libav*/libsw*).
|
|
find "$GITHUB_WORKSPACE/android/buildscripts/prefix/arm64/lib" \
|
|
-maxdepth 1 -type f -name '*.so*' -exec cp -t "$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 built < <(find "$GITHUB_WORKSPACE/android/app/build/outputs/apk" -name '*.apk' -print)
|
|
if [ ${#built[@]} -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
|
|
# One installable APK is enough: the allstorage flavour covers normal
|
|
# playback and full file access, and the universal variant keeps the
|
|
# ABI splits from multiplying the artifact.
|
|
selected=()
|
|
for apk in "${built[@]}"; do
|
|
case "$apk" in *allstorage*universal*) selected+=("$apk") ;; esac
|
|
done
|
|
if [ ${#selected[@]} -eq 0 ]; then
|
|
for apk in "${built[@]}"; do
|
|
case "$apk" in *allstorage*) selected+=("$apk") ;; esac
|
|
done
|
|
fi
|
|
if [ ${#selected[@]} -eq 0 ]; then
|
|
echo "::warning::no allstorage APK found; uploading every variant"
|
|
selected=("${built[@]}")
|
|
fi
|
|
apksigner=$(find "$GITHUB_WORKSPACE/android/buildscripts/sdk" -path '*/build-tools/*/apksigner' -type f -print -quit 2>/dev/null || true)
|
|
for apk in "${selected[@]}"; do
|
|
if [ -n "$apksigner" ]; then
|
|
"$apksigner" verify --print-certs "$apk" | head -2
|
|
fi
|
|
done
|
|
# The player loads its JNI bridge (libplayer.so) before libmpv, and
|
|
# libmpv in turn needs the ffmpeg shared objects; shipping an ABI
|
|
# directory without them produces a crash on the first playback.
|
|
abi=arm64-v8a
|
|
needed="libplayer.so libmpv.so libjoc_core.so libc++_shared.so
|
|
libavcodec.so libavfilter.so libavformat.so libavutil.so
|
|
libavdevice.so libswresample.so libswscale.so"
|
|
for apk in "${selected[@]}"; do
|
|
packaged=$(unzip -l "$apk" | awk -v p="lib/$abi/" '$4 ~ p { print $4 }')
|
|
missing=""
|
|
for lib in $needed; do
|
|
case " $packaged " in *" lib/$abi/$lib "*) ;; *) missing="$missing $lib" ;; esac
|
|
done
|
|
if [ -n "$missing" ]; then
|
|
echo "::error::$apk misses$missing"
|
|
echo "$packaged"
|
|
echo "staged in app/src/main/libs/$abi:"
|
|
ls -l "$GITHUB_WORKSPACE/android/app/src/main/libs/$abi" 2>/dev/null | head -40 || true
|
|
echo "libplayer.so found anywhere in the tree:"
|
|
find "$GITHUB_WORKSPACE/android" -name 'libplayer.so' -print 2>/dev/null | head -10 || true
|
|
exit 1
|
|
fi
|
|
echo "$apk: $(echo "$packaged" | wc -l) shared object(s) packaged"
|
|
done
|
|
cp "${selected[@]}" dist/apk/
|
|
ls -lh dist/apk
|
|
|
|
- name: Upload the Android APK
|
|
if: success()
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: mpv-joc-android-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
|