|
| 1 | +--- |
| 2 | +layout: new-layouts/post |
| 3 | +published: false |
| 4 | +date: 2025-12-18 10:00:00 |
| 5 | +title: "Exploring the Swift SDK for Android" |
| 6 | +author: android-workgroup |
| 7 | +category: "Developer Tools" |
| 8 | +--- |
| 9 | + |
| 10 | +Since the announcement of [the preview Swift SDK for Android a couple months ago](/blog/nightly-swift-sdk-for-android/), |
| 11 | +the Android workgroup has seen a lot of questions about how it works and what's next. |
| 12 | +Please read on for some answers to common questions about the technology and its |
| 13 | +future. |
| 14 | + |
| 15 | +## How Swift works on Android |
| 16 | + |
| 17 | +Swift compiles directly to native machine code on Android, the same way it does on most |
| 18 | +other platforms. This approach produces similar performance to C and C++ code built using the |
| 19 | +Android Native Development Kit (NDK), while achieving a happier balance between performance, |
| 20 | +safety, and usability. To make this possible, Swift apps on Android bundle a native runtime |
| 21 | +that implements many of its features, including its standard library and core |
| 22 | +libraries, like Dispatch and [Foundation](/blog/foundation-preview-now-available/). |
| 23 | + |
| 24 | +However, since most Android APIs are only made available through Java and Kotlin, |
| 25 | +Swift must call into the Android Runtime (ART). That is where the [Java interoperability |
| 26 | +project's](https://github.com/swiftlang/swift-java) `jextract` and `wrap-java` |
| 27 | +tools come in. These tools automatically create bindings that enable you to call |
| 28 | +Swift from Java or go the other way using the Java Native Interface (JNI), which |
| 29 | +allows Swift to seamlessly integrate with the Android platform. |
| 30 | + |
| 31 | +The [`jextract` tool gained a JNI mode this summer](/blog/gsoc-2025-showcase-swift-java/): |
| 32 | +you can now watch its author Mads Odgaard's [Server Side Swift Conference talk from a couple months ago](https://www.youtube.com/watch?v=tOH6V1IvTAc) |
| 33 | +and try out [his new weather example app in the Android examples repository]( |
| 34 | +https://github.com/swiftlang/swift-android-examples/pull/25). (editor: linking his pull |
| 35 | +for now, we'll swap in the link to the final directory once that example is merged later tonight PST) |
| 36 | + |
| 37 | +## Swift on Android in production |
| 38 | + |
| 39 | +While work is still ongoing on official Java interoperability, Android apps built using Swift |
| 40 | +have been in production for many years employing homegrown Java interop, with these apps |
| 41 | +collectively downloaded millions of times. Here are some notable examples: |
| 42 | + |
| 43 | +- [Spark](https://play.google.com/store/apps/details?id=com.readdle.spark) - A popular email client using Swift to share code between mobile iOS/Android and desktop macOS/Windows versions |
| 44 | +- [flowkey](https://play.google.com/store/apps/details?id=com.flowkey.app) - An interactive piano learning app built with Swift for Android for almost a decade |
| 45 | +- [MediQuo](https://play.google.com/store/apps/details?id=com.mediquo.main) - A healthcare app leveraging Swift for cross-platform development |
| 46 | +- [Naturitas](https://play.google.com/store/apps/details?id=com.naturitas.android) - An organic products marketplace running Swift in production |
| 47 | + |
| 48 | +## Ongoing work |
| 49 | + |
| 50 | +Grassroots community efforts to run Swift on Android [began as soon as the language source was opened in 2015](https://lists.swift.org/pipermail/swift-dev/Week-of-Mon-20151207/000171.html), |
| 51 | +and continue to this day. [The Android project board lists areas the workgroup determines important](https://github.com/orgs/swiftlang/projects/17), |
| 52 | +such as easy debugging, now a high priority for us. While it [may work for small examples](https://github.com/swiftlang/llvm-project/issues/10831), |
| 53 | +we need to expand and test it more and make it easy to configure and access. That will likely |
| 54 | +mean tying the debugger and [Swift Language Server Protocol tool, sourcekit-lsp](/blog/gsoc-2025-showcase-code-completion/), |
| 55 | +into Integrated Development Environments (IDEs) like [Visual Studio Code](/blog/gsoc-2025-showcase-swiftly-support-in-vscode/), |
| 56 | +and Android Studio, another issue on our board. |
| 57 | + |
| 58 | +[An Android workflow](https://github.com/swiftlang/github-workflows/pull/172) was |
| 59 | +added to the official Swift workflows for GitHub months ago, allowing you to easily |
| 60 | +try building your Swift packages with the Swift SDK for Android, and work is underway to let you |
| 61 | +[run your tests in an Android emulator](https://github.com/swiftlang/github-workflows/pull/215) |
| 62 | +too. |
| 63 | + |
| 64 | +We are actively looking to onboard more contributors and have set up [a video call this |
| 65 | +weekend to discuss](https://forums.swift.org/t/swift-on-android-new-contributors-call/83729). |
| 66 | +We hope to make these contributor calls a recurring event moving forward, as more people |
| 67 | +pitch in to improving on these Swift tools themselves. |
| 68 | + |
| 69 | +## Sharing Logic Versus Sharing UI |
| 70 | + |
| 71 | +Swift allows you to target many platforms with the same business logic, and Swift |
| 72 | +on Android expands that much more, but we do not provide a cross-platform GUI toolkit. |
| 73 | +As we write in [our draft vision document](https://github.com/swiftlang/swift-evolution/blob/807b844be42db582e434d1667fc907ae7a7a8775/visions/android.md), |
| 74 | +the Android workgroup has no plans to create such a GUI toolkit, but will instead |
| 75 | +curate a list of cross-platform UI tools from the community. |
| 76 | + |
| 77 | +See [our recent post in the Swift forums](https://forums.swift.org/t/swift-gui-toolkits-for-android/83337) |
| 78 | +that lists a handful of popular and in-progress options a preliminary search found, but |
| 79 | +which we have not yet validated regarding what their authors claim. We will work with |
| 80 | +those devs in the coming months to add more info on using their GUI tools with the Swift |
| 81 | +SDK for Android. |
| 82 | + |
| 83 | +## Android API versioning |
| 84 | + |
| 85 | +Until recently, Swift on Android did not support targeting multiple Android API levels |
| 86 | +in the same app, but the recent preview releases now bring the familiar `@available` |
| 87 | +attribute and `#available` runtime check that you know from Apple platforms to Android: |
| 88 | + |
| 89 | +```swift |
| 90 | +#if canImport(Android) |
| 91 | +import Android |
| 92 | +import Dispatch |
| 93 | +#endif |
| 94 | + |
| 95 | +@available(Android 33, *) |
| 96 | +func backtrace() { |
| 97 | + withUnsafeTemporaryAllocation(of: UnsafeMutableRawPointer.self, capacity: 1) { address in |
| 98 | + _ = backtrace(address.baseAddress!, 1) |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +@available(Android 35, *) |
| 103 | +func hello35() { |
| 104 | + print("Hello from API 35") |
| 105 | +} |
| 106 | + |
| 107 | +@available(Android 27, *) |
| 108 | +func hello27() { |
| 109 | + print("Hello, world!") |
| 110 | +} |
| 111 | + |
| 112 | +@main |
| 113 | +struct ExecutableDemo { |
| 114 | + |
| 115 | + static func main() { |
| 116 | + #if os(Android) |
| 117 | + hello27() |
| 118 | + if #available(Android 33, *) { |
| 119 | + backtrace() |
| 120 | + print("Hello from Android API 33+") |
| 121 | + if #available(Android 35, *) { |
| 122 | + hello35() |
| 123 | + } |
| 124 | + } |
| 125 | + #endif |
| 126 | + } |
| 127 | +} |
| 128 | +``` (editor: should we slim this down?) |
| 129 | +Try this new feature out on Android and let us know how it is working for you. |
| 130 | + |
| 131 | +## Learn from the community |
| 132 | + |
| 133 | +Those using Swift on Android for many years have been sharing their experiences, |
| 134 | +as path-breakers like [Readdle](https://readdle.com/blog/swift-for-android-our-experience-and-tools) |
| 135 | +and [Flowkey](https://medium.com/@ephemer/why-we-put-an-app-in-the-android-play-store-using-swift-96ac87c88dfc) |
| 136 | +have written about their work for the last decade. The Left Bit's Pierluigi Cifani |
| 137 | +[wrote about their experiences recently](https://forums.swift.org/t/thoughts-on-swift-for-android/80961), |
| 138 | +gave [a great talk at NSSpain 2025 a couple months ago](https://youtu.be/EIGl6GOo210), |
| 139 | +and was [interviewed by Swift Toolkit last month](https://www.swifttoolkit.dev/posts/dc-pier). |
| 140 | + |
| 141 | +A [community member recently contributed an example app](https://github.com/swiftlang/swift-android-examples/pull/24) |
| 142 | +that builds C++ using CMake and links it with Swift, using Swift's automated JNI bridging |
| 143 | +to Java instead. (editor: not sure we will get this in, but might be a good example to highlight for some) |
| 144 | + |
| 145 | +## Swift 6.3 SDK nightly previews |
| 146 | + |
| 147 | +Finally, we are happy to announce that [an official Swift 6.3 SDK CI](https://ci.swift.org/job/oss-swift-6.3-package-swift-sdk-for-android/) |
| 148 | +has been set up, and it is producing [nightly preview releases of the Swift 6.3 SDK for Android](/install/macos/#swift-sdk-buindles-dev). |
| 149 | +Please follow the [Getting Started guide](/documentation/articles/swift-sdk-for-android-getting-sta |
| 150 | +rted.html) |
| 151 | +to install and use it. (editor: I will update that guide by 3 AM Thursday PST with 6.3 SDK info) |
| 152 | + |
| 153 | +Swift on Android has been a community effort for the last decade, growing |
| 154 | +from the initial patch to apps in production and an active group of developers. |
| 155 | +Try out the new preview releases of the Swift 6.3 SDK for Android and help us |
| 156 | +make it even better! |
0 commit comments