Build the JNI bridge for the Android app

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).
This commit is contained in:
TheM14 committed 2026-10-31 03:52:57 +08:00
1 parent 8673a3b762
commit 5ddbd6154b
2 files changed
+56 -4

No files matched your search

+50
View File
@@ -131,6 +131,30 @@ jobs:
working-directory: android/buildscripts working-directory: android/buildscripts
run: ./buildall.sh --arch arm64 -n mpv 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 - name: Package Android shared libraries
shell: bash shell: bash
run: | run: |
@@ -179,6 +203,8 @@ jobs:
fi fi
libs="$main/libs/$abi" libs="$main/libs/$abi"
mkdir -p "$libs" 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 # This build links the ffmpeg stack dynamically, so the app needs
# every shared object from the cross-build prefix, not just libmpv.so # every shared object from the cross-build prefix, not just libmpv.so
# (libmpv's DT_NEEDED lists libav*/libsw*). # (libmpv's DT_NEEDED lists libav*/libsw*).
@@ -292,6 +318,30 @@ jobs:
"$apksigner" verify --print-certs "$apk" | head -2 "$apksigner" verify --print-certs "$apk" | head -2
fi fi
done 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/ cp "${selected[@]}" dist/apk/
ls -lh dist/apk ls -lh dist/apk
+6 -4
View File
@@ -64,10 +64,12 @@
- `mpv-ad-joc-android-arm64-v8a`:`libmpv.so`、`libjoc_core.so`、`libc++_shared.so`, - `mpv-ad-joc-android-arm64-v8a`:`libmpv.so`、`libjoc_core.so`、`libc++_shared.so`,
给已经自己编好的 mpv 用; 给已经自己编好的 mpv 用;
- `mpv-joc-android-apk`:一个 `app-allstorage-universal-release.apk`,上面这三个库 - `mpv-joc-android-apk`:一个 `app-allstorage-universal-release.apk`,由 `assembleRelease`
已经打进 mpv-android 的 `libs/arm64-v8a/`,由 `assembleRelease` 打包并签名, 打包并签名,直接可装。包里的 `libplayer.so` 由 `ndk-build` 现编(`app/src/main/jni`),
直接可装。mpv-android 本身会出 `default` / `allstorage` × `arm64-v8a` / `universal` `libmpv.so` 和 ffmpeg 的 `libav*` / `libsw*` 一起放进 `libs/arm64-v8a/`;`ndk.properties`
四个包,CI 只保留 allstorage 的 universal 版:权限最全,ABI 拆包也不会让工件变多。 让 AGP 用 NDK 的 strip 处理这些库。mpv-android 本身会出 `default` / `allstorage`
× `arm64-v8a` / `universal` 四个包,CI 只保留 allstorage 的 universal 版:权限最全,
ABI 拆包也不会让工件变多。
签名用的是 CI 现场生成的临时 keystore(`-Pandroid.injected.signing.*`),只保证可安装, 签名用的是 CI 现场生成的临时 keystore(`-Pandroid.injected.signing.*`),只保证可安装,
不代表发布身份;要正式分发就把这段换成仓库 secret 里的 keystore。APK 里仍是原版 不代表发布身份;要正式分发就把这段换成仓库 secret 里的 keystore。APK 里仍是原版