This repository was archived by the owner on Nov 10, 2026. It is now read-only.
Repository navigation
Point swiftbuild at the Swift SDK's bundled NDK via ANDROID_NDK_HOME - #278
Merged
marcprux merged 1 commit intoSep 19, 2026
Merged
Conversation
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.
Member
|
Nice catch, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Swift 6.4 makes
swiftbuildthe default SwiftPM engine. Its Android platform plugin does not read the Swift SDK'ssdkRootPath; it resolves the NDK fromANDROID_NDK_ROOT, thenANDROID_NDK_HOME, then the NDK versions underANDROID_HOME.skip android build/testclearsANDROID_NDK_ROOT(#207 workaround) and sets nothing else, so on any machine whereANDROID_HOMEcarries 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:(
__hash_memoryis exported by r30'slibc++_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, whenANDROID_NDK_HOMEis unset, set it to theandroid-ndk-*directory thatskip android sdk installunpacks next to the SDK'sndk-sysroot(tc.sysrootDir.deletingLastPathComponent()). Callers who set their ownANDROID_NDK_HOMEare untouched;ANDROID_NDK_ROOThandling is unchanged.Verified
Exporting
ANDROID_NDK_HOME=<bundle>/swift-android/android-ndk-r30from a wrapper script beforeskip android test(macOS host, skip 1.9.10, Swift 6.4.0 SDK, bridged multi-module package, defaultswiftbuildengine): 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/outfrom a mis-linked run needs to be cleared before the change takes effect.Companion to #277 (swiftbuild
.bundleresource folders); together they let a Skip Fuse package runskip android teston Swift 6.4 without--build-system native.Workaround until this ships
skip already forwards
ANDROID_NDK_HOMEtoswift builduntouched, so on the released 1.9.10 you can point it at the NDK thatskip android sdk installunpacked next to the SDK:ANDROID_NDK_HOME, notANDROID_NDK_ROOT: skip clears the latter before invokingswift build..build/out(and.build/manifest.pif) first; swift-build keeps the sysroot in its cached build description.swift-<version>-RELEASE_android.artifactbundle/swift-android/android-ndk-<rNN>. In CI containers SwiftPM extracts under/root/.swiftpmeven whenHOMEis remapped.--build-system nativealso avoids the problem (it uses the SDK's own sysroot) but is deprecated in SwiftPM 6.4.