From 8ed49a11709cf0c09b22271a78aeafbe7618a2a9 Mon Sep 17 00:00:00 2001 From: TheM14 Date: Sat, 31 Oct 2026 03:05:03 +0800 Subject: [PATCH] Locate the Android SDK and the library directory the way the build 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/ while recreating the alias. --- .github/workflows/build-android.yml | 43 ++++++++++++++++++----------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-android.yml b/.github/workflows/build-android.yml index fbbc189..791ce75 100644 --- a/.github/workflows/build-android.yml +++ b/.github/workflows/build-android.yml @@ -166,18 +166,18 @@ jobs: run: | set -euo pipefail abi=arm64-v8a - jni="$GITHUB_WORKSPACE/android/app/src/main/jniLibs" - # The checkout carries this path as a symlink (pointing at a prefix - # directory for an ABI we do not build), and mkdir -p refuses a - # dangling link with "File exists". Replace it with a plain directory. - if [ -L "$jni" ]; then - echo "jniLibs is a symlink to $(readlink "$jni" 2>/dev/null || echo '?'); replacing it" - rm -f "$jni" - elif [ -e "$jni" ] && [ ! -d "$jni" ]; then - echo "jniLibs is a file; replacing it with a directory" - rm -f "$jni" + 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="$jni/$abi" + 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/" @@ -186,6 +186,9 @@ jobs: -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 @@ -201,26 +204,34 @@ jobs: run: | set -euo pipefail # download-sdk.sh unpacks the SDK under android/buildscripts/sdk; find - # the root by its platforms/ directory instead of hard-coding the name. + # 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 2 -type d | head -40 + 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. - if [ -x "$sdk_dir/cmdline-tools/latest/bin/sdkmanager" ]; then - yes | "$sdk_dir/cmdline-tools/latest/bin/sdkmanager" \ - --sdk_root="$sdk_dir" --licenses >/dev/null 2>&1 || true + 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-; AGP looks it up by the # source.properties revision under ndk/, so link it there too.