7

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.

4
  • 1
    Even if you could, the platforms are so different that you'd need to completely rewrite the UI, storage, threading, etc. You could at most share business logic between them, but to do that you'd need to be set up to separate that out. Which is unlikely unless you architected it from the start. May 26, 2020 at 15:10
  • 1
    Google recently announced Kotlin's multiplatform support again as Gabe Sechan said, its only to share business logic not UI, you can dig a bit deeper into that to find code resuability but if you wanna keep common code cross platform programming languages like react native, flutter should do good job for you May 26, 2020 at 15:13
  • Yeah, it seems like the best way to have one code for both OS is to rewrite the appp in a different language. May 26, 2020 at 15:43
  • SCADE 2 as a cross platform
    – mercury
    Nov 23, 2021 at 3:24

2 Answers 2

12

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.

-4

You cant convert swift code to java code. There are languages and frameworks that allow to write for both Android or IOS using same language. Such platforms are fully native, or half native(hybrid), or web-based.

If we talk about swift - its native for ios, so you can't generate android from it.

In future you can use flutter or React Native or Kotlin with plugins to write for both platforms.

Unfortunately, you will have to rewrite it for Android.

3
  • 1
    Hi Andrei, I wasn't really looking to convert Swift to Java, I actually wanted to know if there is any way to compile an apk from Swift. My first instinct would be to go to react native, ios or xamarin. Unfortunately I "inherited" swift code (nothing against the language). so instead of rewriting I'm tryng to find out if I can reuse it. May 26, 2020 at 15:42
  • Unfortunately, I never heard of any converters or compilers like that. I ve heard about visa-versa, android-ios, but never tested this. MechDome , if you are interested to check. May 26, 2020 at 15:51
  • The OP asked specifically for building Swift for Android, not for other programming languages. Answers that merely mention other languages and don't answer the question at hand belong to other threads like this one.
    – Jeehut
    Nov 20, 2020 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.