Search code examples
androidswiftapk

Compiling Swift for Android


Recently I have been trying to check if there is a way to generate an APK from swift code.

After some research I've noticed that there are quite a few threads up to a couple years ago and then it just died. Is that due to some issue? Is it still possible?

In my case, I've already have an xcode project which I wish to migrate to android, but if possible I would like to have just one source code instead of 2.


Solution

  • While compiling Swift code for Android and even creating an .apk file is still far away from being easy, it is technically possible. From the way you're asking this question though, I expect you to be more on the "user space" of programming languages rather than knowing enough compiler details to get it working in a reasonable time and maintaining it with all the fast-paced changes happening.

    So the more realistic answer for you probably is, that it's currently not possible.

    But a lot of work is currently going on in the Swift community to drive support for more platforms forward in many ways, both to make building Swift very easy on more platforms and also to provide frameworks for creating UIs and integrating with the system properly (as Swift is just a programming language and there's more to an app than just programming logic).

    Here are a few links for further reading:

    1. "Getting Started with Swift on Android" from the Swift GitHub repository
    2. Blog posts from Realm (2017) and Readdle (2018) explaining what's needed for Android apps
    3. Most viewed threads for the Android tag on the official Swift Forums
    4. "On the road to Swift 6" post, explaining how Swift will expand in the near future
    5. A community-driven port of UIKit for Android (work in progress)
    6. Ports of SwiftUI (OpenSwiftUI, Tokamak) that don't support Android yet, but might do later

    I hope this gives a good overview about the current state of Swift for Android.