Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Swift for Android

Tags:

android

swift

apk

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.

like image 980
Paulo Künzel Avatar asked May 26 '20 15:05

Paulo Künzel


People also ask

Can you compile Swift to Android?

Getting Started with Swift on Android. The Swift standard library (stdlib) can be compiled for Android armv7, x86_64, and aarch64 targets, which makes it possible to execute Swift code on a mobile device running Android or an emulator.

Does Android use Swift?

Fusion is able to automatically generate Swift API to enable access to the Android Java APIs. Fusion provides you with with Swift SPM libraries that mimic every Android Java API call. On iOS, Fusion is just a wrapper around Apple iOS SDK to provide developers with abstractions common to both platforms.

Can Xcode be used for Android?

As Xcode is only compatible with Mac OS, you cannot use other computers and operating systems.


1 Answers

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.

like image 189
Jeehut Avatar answered Sep 30 '22 10:09

Jeehut