Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 27 additions & 7 deletions .github/workflows/scripts/install-and-build-with-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I want ndk28c, and it finds a "28*" directory, it will check the source.properties file to make sure it is really "ndk28c", and if so, use it. Otherwise (e.g., if it is "ndk28a"), fall back to downloading it as if a matching cache directory did not exist. Correct?

Copy link
Member Author

@finagolfin finagolfin Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, exactly 👍

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
Expand Down