Skip to content

Auto-detect installed Android Swift SDK artifactbundle - #50

Open
otondin wants to merge 1 commit into
swiftlang:mainfrom
otondin:fix/android-sdk-version-autodetect
Open

Auto-detect installed Android Swift SDK artifactbundle#50
otondin wants to merge 1 commit into
swiftlang:mainfrom
otondin:fix/android-sdk-version-autodetect

Conversation

@otondin

@otondin otondin commented Jul 28, 2026

Copy link
Copy Markdown

Fixes #42

…ssing its name

All four Swift/Android build scripts (swift-android.gradle.kts and the
copy-pasted Groovy build.gradle files in hello-cpp-swift/swift-lib,
hello-swift-java/hashing-lib, and swift-java-weather-app/weather-lib)
guessed the installed Android Swift SDK artifactbundle directory name as
"swift-${swiftVersion}-RELEASE_android.artifactbundle". In practice `swift
sdk install` names the bundle after the exact resolved patch version (e.g.
requesting "6.3" installs "swift-6.3.3-RELEASE_android.artifactbundle"),
so the guessed path silently didn't exist for most users.

This caused two distinct failures depending on where the wrong path was
used:
- swiftBuild*/-resource-dir: `swift build` failed outright with "unable
  to load standard library for target ..." (hello-swift-raw-jni-callback).
- copyJniLibs' Copy task: silently dropped every Swift runtime .so
  (libswiftCore, libswiftSwiftOnoneSupport, libc++_shared, ...) from the
  from(...) sources instead of failing, since Gradle's Copy task doesn't
  error on missing sources. The app built and installed fine but crashed
  on the first Swift call with dlopen failures (hello-swift-java).

Both are reported in swiftlang#42.

Replace the guess with resolveAndroidSdkVersion(), which scans the Swift
SDK directory for installed "*android*.artifactbundle" folders instead of
assuming a naming scheme: a single match is used as-is (covers the common
case of one SDK installed, any naming convention including snapshots), and
among multiple matches the one starting with the configured swiftVersion
is preferred, falling back to the most recently installed. An explicit
SWIFT_ANDROID_SDK_VERSION override, or a directory with no matches, still
behaves as before.

Verified by rebuilding native-activity and hello-swift-java-hashing-app
from a clean environment with SWIFT_ANDROID_SDK_VERSION unset: both now
correctly locate swift-6.3.3-RELEASE_android.artifactbundle and the
hashing app's jniLibs directory includes the previously-missing runtime
libraries.

Fixes swiftlang#42

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hhgbd7ipopFKHSKWWnC4UH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android Studio can't run hello-swift-java and can't even build hello-swift-raw-jni-callback

1 participant