From 36c70357310389ea6b01f71863e7262fe98d2135 Mon Sep 17 00:00:00 2001 From: Finagolfin Date: Fri, 13 Feb 2026 14:35:48 +0530 Subject: [PATCH 1/2] Check if the locally installed Android NDK matches the configured NDK version We were never actually checking `android_ndk_versions` if ANDROID_NDK_HOME was set, as that environment variable always will be on the github runners. Also, since GitHub often has other NDKs installed too, check if a matching one is installed and use it, plus add some log output so we can verify all this easily from now on. --- .../scripts/install-and-build-with-sdk.sh | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/scripts/install-and-build-with-sdk.sh b/.github/workflows/scripts/install-and-build-with-sdk.sh index 086ff168..ef6eacba 100755 --- a/.github/workflows/scripts/install-and-build-with-sdk.sh +++ b/.github/workflows/scripts/install-and-build-with-sdk.sh @@ -627,6 +627,16 @@ ANDROID_SDK_DOWNLOAD_ROOT="${SWIFT_DOWNLOAD_ROOT}/${SWIFT_VERSION_BRANCH}/androi STATIC_LINUX_SDK_DOWNLOAD_ROOT="${SWIFT_DOWNLOAD_ROOT}/${SWIFT_VERSION_BRANCH}/static-sdk" WASM_SDK_DOWNLOAD_ROOT="${SWIFT_DOWNLOAD_ROOT}/${SWIFT_VERSION_BRANCH}/wasm-sdk" +install_android_ndk() { + local ndk_version="$1" + log "Installing Android NDK: $ndk_version" + curl_with_retry -fsSL -o ndk.zip https://dl.google.com/android/repository/android-ndk-"${ndk_version}"-"$(uname -s)".zip + command -v unzip >/dev/null || install_package unzip + unzip -q ndk.zip + rm ndk.zip + export ANDROID_NDK_HOME="${PWD}"/android-ndk-"${ndk_version}" +} + install_android_sdk() { # Check if the Android Swift SDK is already installed if "$SWIFT_EXECUTABLE_FOR_ANDROID_SDK" sdk list 2>/dev/null | grep -q "^${ANDROID_SDK_TAG}_android"; then @@ -653,18 +663,28 @@ install_android_sdk() { # guess some common places where the swift-sdks file lives cd ~/Library/org.swift.swiftpm || cd ~/.config/swiftpm || cd ~/.local/swiftpm || cd ~/.swiftpm || cd /root/.swiftpm + # permit the "--android-ndk" flag to override the default + local android_ndk_version="${ANDROID_NDK_VERSION:-r27d}" + log "Checking for Android NDK $android_ndk_version at $ANDROID_NDK_HOME" + # Download and install the Android NDK. # Note that we could use the system package manager, but it is # named different things for different distributions # (e.g., "google-android-ndk-r26-installer" on Debian) if [[ ! -d "${ANDROID_NDK_HOME:-}" ]]; then - # permit the "--android-ndk" flag to override the default - local android_ndk_version="${ANDROID_NDK_VERSION:-r27d}" - curl_with_retry -fsSL -o ndk.zip https://dl.google.com/android/repository/android-ndk-"${android_ndk_version}"-"$(uname -s)".zip - command -v unzip >/dev/null || install_package unzip - unzip -q ndk.zip - rm ndk.zip - export ANDROID_NDK_HOME="${PWD}"/android-ndk-"${android_ndk_version}" + install_android_ndk "$android_ndk_version" + elif ! grep -q "Pkg.ReleaseName = ${android_ndk_version}" "${ANDROID_NDK_HOME}/source.properties"; then + log "Android NDK $android_ndk_version did not match $(grep "Pkg.ReleaseName" "$ANDROID_NDK_HOME/source.properties")" + # Check if the correct NDK is already cached in the same directory, as + # it often is on GitHub runners, and use it if so + ndk_release=$(echo "$android_ndk_version" | tr -d "[:alpha:]") + try_ndk_path=$(find "$(dirname "${ANDROID_NDK_HOME}")" -name "${ndk_release}*" -maxdepth 1) + if [[ -d "${try_ndk_path}" ]] && grep -q "Pkg.ReleaseName = ${android_ndk_version}" "${try_ndk_path}/source.properties"; then + log "Found a matching Android NDK $android_ndk_version at $try_ndk_path instead" + export ANDROID_NDK_HOME="$try_ndk_path" + else + install_android_ndk "$android_ndk_version" + fi fi ./swift-sdks/"${android_sdk_bundle_name}"/swift-android/scripts/setup-android-sdk.sh From a8044d7da40283fed0a3c03679e98654a14585f0 Mon Sep 17 00:00:00 2001 From: Finagolfin Date: Sun, 15 Feb 2026 16:31:49 +0530 Subject: [PATCH 2/2] [CI] Add back Android flag needed to build it, and build against NDK 28c instead --- .github/workflows/pull_request.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 28c5cb73..12334c05 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -52,7 +52,9 @@ jobs: # Android android_sdk_pre_build_command: | cd tests/TestPackage + enable_android_sdk_build: true enable_android_sdk_checks: true + android_ndk_versions: "[\"r28c\"]" # Windows windows_build_command: | cd tests/TestPackage