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.
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.
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.
As Xcode is only compatible with Mac OS, you cannot use other computers and operating systems.
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:
Android
tag on the official Swift ForumsI hope this gives a good overview about the current state of Swift for Android.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With