Skip to content
This repository was archived by the owner on Nov 10, 2026. It is now read-only.

Point swiftbuild at the Swift SDK's bundled NDK via ANDROID_NDK_HOME - #278

Merged
marcprux merged 1 commit into
skiptools:mainfrom
piercifani:android-build-ndk-home-from-swift-sdk
Sep 19, 2026
Merged

marcprux merged 1 commit into
skiptools:mainfrom
piercifani:android-build-ndk-home-from-swift-sdk

Conversation

@piercifani

@piercifani piercifani commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Swift 6.4 makes swiftbuild the default SwiftPM engine. Its Android platform plugin does not read the Swift SDK's sdkRootPath; it resolves the NDK from ANDROID_NDK_ROOT, then ANDROID_NDK_HOME, then the NDK versions under ANDROID_HOME. skip android build/test clears ANDROID_NDK_ROOT (#207 workaround) and sets nothing else, so on any machine where ANDROID_HOME carries Android Studio's NDK, Swift compiles against the SDK's bundled NDK but links with -sysroot <Android Studio NDK>. With the Swift 6.4.0 SDK (NDK r30) and Android Studio's NDK 28 the test-runner link fails:

ld.lld: error: undefined reference: std::__ndk1::__hash_memory(void const*, unsigned long)

(__hash_memory is exported by r30's libc++_shared.so, not by 28's; OpenCombine's C++ helper picks it up from the r30 headers.) The same package links fine with --build-system native, which uses the SDK's sysroot.

Change

In runToolchainCommand, when ANDROID_NDK_HOME is unset, set it to the android-ndk-* directory that skip android sdk install unpacks next to the SDK's ndk-sysroot (tc.sysrootDir.deletingLastPathComponent()). Callers who set their own ANDROID_NDK_HOME are untouched; ANDROID_NDK_ROOT handling is unchanged.

Verified

Exporting ANDROID_NDK_HOME=<bundle>/swift-android/android-ndk-r30 from a wrapper script before skip android test (macOS host, skip 1.9.10, Swift 6.4.0 SDK, bridged multi-module package, default swiftbuild engine): all 226 Android compile/link commands switch to the bundled r30 sysroot and the test runner links and runs. This PR does the same from inside skip. One caveat worth knowing: swift-build bakes the NDK into its cached build description, so an existing .build/out from a mis-linked run needs to be cleared before the change takes effect.

Companion to #277 (swiftbuild .bundle resource folders); together they let a Skip Fuse package run skip android test on Swift 6.4 without --build-system native.

Workaround until this ships

skip already forwards ANDROID_NDK_HOME to swift build untouched, so on the released 1.9.10 you can point it at the NDK that skip android sdk install unpacked next to the SDK:

export ANDROID_NDK_HOME="$HOME/.swiftpm/swift-sdks/swift-6.4.0-RELEASE_android.artifactbundle/swift-android/android-ndk-r30"
skip android test --package-path <package>
  • Use ANDROID_NDK_HOME, not ANDROID_NDK_ROOT: skip clears the latter before invoking swift build.
  • If a build already ran against the wrong NDK, delete .build/out (and .build/manifest.pif) first; swift-build keeps the sysroot in its cached build description.
  • The path follows the installed SDK: swift-<version>-RELEASE_android.artifactbundle/swift-android/android-ndk-<rNN>. In CI containers SwiftPM extracts under /root/.swiftpm even when HOME is remapped.
  • --build-system native also avoids the problem (it uses the SDK's own sysroot) but is deprecated in SwiftPM 6.4.

The native SwiftPM engine compiles and links against the Swift Android SDK's
sdkRootPath (ndk-sysroot). The swiftbuild engine, the default since Swift 6.4,
ignores that and discovers an NDK itself: ANDROID_NDK_ROOT, else
ANDROID_NDK_HOME, else the NDKs under ANDROID_HOME. skip clears ANDROID_NDK_ROOT
and sets nothing, so on a machine whose ANDROID_HOME holds Android Studio's NDK
the Swift code is compiled against the SDK's NDK r30 but linked with
-sysroot <NDK 28>, and the test-runner link fails:

  ld.lld: error: undefined reference: std::__ndk1::__hash_memory(void const*, unsigned long)

When the caller has not set ANDROID_NDK_HOME, set it to the android-ndk-* folder
that `skip android sdk install` unpacked next to the SDK's sysroot. Verified on
a bridged multi-module package with skip 1.9.10 / Swift 6.4.0: with the variable
swiftbuild links every Android command against the bundled r30 sysroot and the
tests run.
@cla-bot cla-bot Bot added the cla-signed label Sep 18, 2026
@marcprux
marcprux merged commit 45d5356 into skiptools:main Sep 19, 2026
26 of 33 checks passed
@marcprux

Copy link
Copy Markdown
Member

Nice catch, thanks!

@piercifani
piercifani deleted the android-build-ndk-home-from-swift-sdk branch September 20, 2026 08:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants