Announcing the Swift SDK for Android

Swift has matured significantly over the past decade — extending from cloud services to Windows applications, browser apps, and microcontrollers. Swift powers apps and services of all kinds, and thanks to its great interoperability, you can share code across platforms.

The Android workgroup is an open group, free for anyone to join, that aims to expand Swift to Android. Today, we are pleased to announce nightly preview releases of the Swift SDK for Android.

This milestone reflects months of effort by the Android workgroup, building on many years of grassroots community effort. With the SDK, developers can begin developing Android applications in Swift, opening new avenues for cross-platform development and accelerating innovation across the mobile ecosystem.

The Swift SDK for Android is available today, bundled with the Windows installer or downloadable separately for use on Linux or macOS.

Getting Started

We've published a Getting Started guide to help you set up your first native Swift code on an Android device. The Swift for Android Examples help demonstrate end‑to‑end application workflows on Android.

With the Swift SDK for Android, you can now start porting your Swift packages to Android. Over 25% of packages in the Swift Package Index already build for Android, and the Community Showcase now indicates Android compatibility.

The swift-java project enables you to interoperate between Java and Swift. It is both a library and a code generator, enabling you to integrate Swift and Java in both directions by automatically generating safe and performant bindings. To learn about generating bindings to bring your business logic to Android, check out the recent Swift Server Side meetup talk by Mads Odgaard.

Next Steps

This preview release opens many new opportunities to continue improving these tools. We encourage you to discuss your experiences, ideas, tools and apps on the Swift Forums in the Android Category.

The Android workgroup is drafting a vision document, currently under review, for directing future work regarding Swift on Android. This vision will outline priority areas and guide community efforts to maximize impact across the ecosystem. In addition, we maintain a project board that tracks the status of major efforts, as well as official CI for the Swift SDK for Android.

If you're as excited as we are, join us and help make this ecosystem even better!

34 Likes

I was excited to see the official announcement for Swift on Android examples, though I was a bit sad not to have been included.

For context, the Android team previously reached out to me about using my examples. I was happy to assist, providing all my code, additional information, and an offer for further help. While it was disappointing to learn of their final decision through the public announcement without a direct response, I want to continue channeling my efforts positively into the community.

If your goal is to build a full Swift or hybrid Swift+Java Android application - packaged into an APK without using the standard Kotlin/Java/Gradle/Android Studio - my repositories may be useful. This approach is particularly helpful for iOS developers or those new to Android, as it doesn't require learning new knowledge about new development tools.

To complement the official announcement, you are welcome to explore my repositories if you wish to build a full Swift or Swift+Java Android application packed into an APK.

I believe I currently offer the only solution for direct SwiftPM to APK packaging. Furthermore, my examples are the only ones that provide full Swift Concurrency support with a working @MainActor or DispatchQueue.main, which can significantly help in adapting libraries that rely heavily on regular main-thread switching context code syntax.

Here are my most relevant example:

  • android-example - My most complete and complex minimal application. It demonstrates a Swift or Swift+Java application with touch, mouse, gamepad, keyboard or system events and painting window buffer with colors. For a 100% Swift application, you can simply comment out the JAVA and ACTIVITY variables in the Makefile. To use Foundation libraries uncomment FOUNDATION variable.

I have also developed these standalone Swift libraries to make development smoother:

  • ndk - Simplifies importing Android C headers, eliminating the need to write "CTarget" wrappers.
  • native-activity - Provides Swift-friendly structs and enums for working with Android's NativeActivity.
  • android-assets - For loading assets and documents directly from the APK bundle.
  • java - A stable, working alternative to the currently crashing on Android official swift-java tool.

For reference, here are the legacy examples I previously provided on the forum, which have now been replaced by the android-example above:

  • android-example-c - Uses google's native-app-glue C code similar to official example. It was rewritten in android-example above to 100% Swift code with @MainActor entry point and isolation to application lifecycle.
  • android-example-java - Just regular Android Java app with Swift functions import to Java and Java to Swift.

I am also currently working on a cross-platform macOS-iOS-Android example with a UI (using OpenGL on Android and OpenGL/Metal on Apple platforms). I hope to share it with the community soon and eventually adapt it for Linux.

If anyone encounters issues with these projects or needs help getting started, please don't hesitate to reach out. I will do my best to provide support, as I am truly amazed by the freedom Android offers and am keen to help popularize Swift on this platform.

13 Likes