Skip to content

Respect ANDROID_SDK_ROOT and ANDROID_NDK_ROOT env vars to override the Android SDK and/or NDK locations #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jakepetroules opened this issue May 7, 2025 · 3 comments
Labels
android Support for the Android platform

Comments

@jakepetroules
Copy link
Collaborator

Currently Swift Build discovers the Android SDK and NDK under the default paths on each platform:

  • Windows: %LOCALAPPDATA%\Android\Sdk
  • macOS: ~/Library/Android/sdk
  • Linux: ~/Android/Sdk

If ANDROID_SDK_ROOT and/or ANDROID_NDK_ROOT are set in the environment, those should override the default SDK and NDK location lookup, respectively.

@jakepetroules jakepetroules added the android Support for the Android platform label May 7, 2025
@marcprux
Copy link

Note that ANDROID_NDK_ROOT is currently consulted, but in a way that breaks Android builds, at least on macOS and Linux. We currently need to explicitly un-set the environment in order to build for Android.

If we could solve the long-standing swiftrt.o issue, then ideally we could eliminate the "ndk-root" link script that we're using (see swiftlang/swift-docker#467 (comment)) and just default the sdkRootPath (which probably ought to be optional, but isn't) to use the ANDROID_NDK_ROOT environment, and everything would just work.

@jakepetroules
Copy link
Collaborator Author

Note that ANDROID_NDK_ROOT is currently consulted, but in a way that swiftlang/swift-driver#1879, at least on macOS and Linux. We currently need to explicitly un-set the environment in order to build for Android.

You're talking about swift-driver, but this issue is about Swift Build. We still need to consult ANDROID_NDK_ROOT here at this level in order to look up various locations correctly. One reason is because Swift Build will explicitly pass --sysroot to the Swift driver regardless of whether ANDROID_NDK_ROOT is set.

It sounds like your #1879 PR will fix the swift-driver issue though, right? Shall we move that out of draft and get it landed?

@marcprux
Copy link

I've moved swiftlang/swift-driver#1879 out of draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Support for the Android platform
Projects
None yet
Development

No branches or pull requests

2 participants