Skip to content

Commit f993b45

Browse files
committed
Check if the locally installed Android NDK matches the wanted 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 check all this info easily from now on.
1 parent c188fe5 commit f993b45

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

.github/workflows/scripts/install-and-build-with-sdk.sh

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,16 @@ ANDROID_SDK_DOWNLOAD_ROOT="${SWIFT_DOWNLOAD_ROOT}/${SWIFT_VERSION_BRANCH}/androi
627627
STATIC_LINUX_SDK_DOWNLOAD_ROOT="${SWIFT_DOWNLOAD_ROOT}/${SWIFT_VERSION_BRANCH}/static-sdk"
628628
WASM_SDK_DOWNLOAD_ROOT="${SWIFT_DOWNLOAD_ROOT}/${SWIFT_VERSION_BRANCH}/wasm-sdk"
629629

630+
install_android_ndk() {
631+
local ndk_version="$1"
632+
log "Installing Android NDK: $ndk_version"
633+
curl_with_retry -fsSL -o ndk.zip https://dl.google.com/android/repository/android-ndk-"${ndk_version}"-"$(uname -s)".zip
634+
command -v unzip >/dev/null || install_package unzip
635+
unzip -q ndk.zip
636+
rm ndk.zip
637+
export ANDROID_NDK_HOME="${PWD}"/android-ndk-"${ndk_version}"
638+
}
639+
630640
install_android_sdk() {
631641
# Check if the Android Swift SDK is already installed
632642
if "$SWIFT_EXECUTABLE_FOR_ANDROID_SDK" sdk list 2>/dev/null | grep -q "^${ANDROID_SDK_TAG}_android"; then
@@ -653,18 +663,27 @@ install_android_sdk() {
653663
# guess some common places where the swift-sdks file lives
654664
cd ~/Library/org.swift.swiftpm || cd ~/.config/swiftpm || cd ~/.local/swiftpm || cd ~/.swiftpm || cd /root/.swiftpm
655665

666+
# permit the "--android-ndk" flag to override the default
667+
local android_ndk_version="${ANDROID_NDK_VERSION:-r27d}"
668+
log "Checking for Android NDK $android_ndk_version at $ANDROID_NDK_HOME"
669+
656670
# Download and install the Android NDK.
657671
# Note that we could use the system package manager, but it is
658672
# named different things for different distributions
659673
# (e.g., "google-android-ndk-r26-installer" on Debian)
660674
if [[ ! -d "${ANDROID_NDK_HOME:-}" ]]; then
661-
# permit the "--android-ndk" flag to override the default
662-
local android_ndk_version="${ANDROID_NDK_VERSION:-r27d}"
663-
curl_with_retry -fsSL -o ndk.zip https://dl.google.com/android/repository/android-ndk-"${android_ndk_version}"-"$(uname -s)".zip
664-
command -v unzip >/dev/null || install_package unzip
665-
unzip -q ndk.zip
666-
rm ndk.zip
667-
export ANDROID_NDK_HOME="${PWD}"/android-ndk-"${android_ndk_version}"
675+
install_android_ndk "$android_ndk_version"
676+
elif [[ ! $(grep -q "Pkg.ReleaseName = ${android_ndk_version}" "${ANDROID_NDK_HOME}/source.properties") ]]; then
677+
log "Android NDK $android_ndk_version did not match $(grep "Pkg.ReleaseName" "$ANDROID_NDK_HOME/source.properties")"
678+
# Check if the correct NDK is already cached in the same directory, as
679+
# it often is on GitHub runners, and use it if so
680+
local try_ndk_path=$(find "${ANDROID_NDK_HOME}/.." -name "$(echo $android_ndk_version | tr -d "[:alpha:]")*" -maxdepth 1)
681+
if [[ -d "${try_ndk_path}" && $(grep -q "Pkg.ReleaseName = ${android_ndk_version}" "${try_ndk_path}/source.properties") ]]; then
682+
log "Found a matching Android NDK $android_ndk_version at $try_ndk_path instead"
683+
export ANDROID_NDK_HOME="$try_ndk_path"
684+
else
685+
install_android_ndk "$android_ndk_version"
686+
fi
668687
fi
669688

670689
./swift-sdks/"${android_sdk_bundle_name}"/swift-android/scripts/setup-android-sdk.sh

0 commit comments

Comments
 (0)