Introducing Swift4j and Our Vision for Swift on Android

Hello Swift Developers,

We are SCADE, a team passionate about enabling Swift developers to build cross-platform applications. Starting with version 2.0, we have been building a dedicated Swift Toolchain for Android, and we are excited to see the community's efforts toward an official Swift release for Android as well.

Initially, we aimed to create a full-featured framework for cross-platform development. However, based on our experience, we realized that sharing non-UI code between platforms is more practical and impactful.
Especially today, with the availability of powerful tools, both AI-driven and traditional, for generating user interfaces from existing designs across multiple platforms. It led us to concentrate on the Swift toolchain for Android and tooling that simplifies the integration of Swift Packages into Android applications, which we collectively refer to as the SCADE App Logic.

One of our key contributions is the swift4j library, which enables seamless interoperability between Swift and Java/Kotlin. Alongside this, we developed SwiftPM Gradle plugins to streamline the integration of Swift code into Android and other JVM-based projects.

Looking ahead, we plan to integrate the official Swift Toolchain into our SwiftPM Gradle plugin, further enhancing the developer experience for Swift on Android. Additionally, we aim to simplify access to the Android API from Swift. While we have made progress in this area with earlier versions of Swift, we are committed to improving and updating this functionality to align with the latest Swift versions.

We invite you to explore our examples and provide feedback. Check out the following resources:

We look forward to hearing your thoughts and collaborating with the community to make Swift on Android even better!

Best regards,
The SCADE Team

11 Likes

Great to hear from you, Grigory! We (the Android Workgroup) have been discussing the topic of Java/Kotlin interoperability a lot recently (see Android, Java, and SwiftJNI), in collaboration with @ktoso and the Swift Java effort. We would certainly love your additional insights and recommendations.

You might consider joining an upcoming workgroup call and/or dropping into the Android channel on the Swift Open Source Slack.

6 Likes

Hi Grigory,
thanks for reaching out!

As Marc mentioned, I'm maintaining Swift's Java interoperability effort "SwiftJava" over here: swiftlang/swift-java. If you've not seen it yet, we did a quick overview of all the features during WWDC (video), and there's some other talks we did about the foreign memory APIs but that would not be applicable for Android so far.

I've skimmed the projects you linked a little bit and I see there's a lot of overlap with what we're working on specifically in the macros approach.

I'm wondering how we could collaborate given the large overlap. Would you be open to contributing to the Swift project's Java interop repo? We're really focused on getting all the "edge cases" right, so I'd love to get more folks collaborating on ironing out all those edge cases in one place.

SwiftJava offers a few modes in which it supports interop. Your work seems most similar to the macros we're offering and are currently collectively named JavaKit (may be renamed soon to SwiftJNI, still pondering that). There's an example app here: JavaKitExample.

It seems to me this is the place where we could collaborate the most!

If you'd like to chat how we could get that collaboration going I'd love to chat, you can message me directly or use the Slack instance Marc mentioned above.

--

Separately, we also offer a mode that are more aimed towards using Swift from Java using Java source generation (swift-java jextract) in order to have a "shared core" in Swift. You're correctly noting that that's where a lot of the potential lies IMHO, so we've been working on this along with @madsodgaard to give it a JNI mode, and we've made a lot of progress; Here's a list of supported features already; so that's a different approach, but also very complementary to the general strategy.

I saw you also did some basic gradle plugins, that's something we're going to be working on as well, so I'd like to invite you to collaborate on swift-java so we can have one set of really solid tools here. The simple things like just invoking SwiftPM are not that hard, but we're also going to need to work on packaging up jars with different platform dynamic libraries etc etc.

Overall I'd love to find ways to collaborate, so let's find a way we can chat plans here and figure out how we can help eachother out.

7 Likes

Hi Marc and Konrad,

Thank you for your prompt answer and the invitation to join the working group; I will do so immediately !

I first saw the (swift-java)[ GitHub - swiftlang/swift-java: Java interopability support for Swift ] project about a year ago, but since then I have seen a lot of progress. I will take a closer look at it.

Is there any code generation for Java -> Swift bridging? We worked on code generation for the Android API for the 4.x version of Swift, and I'm looking into different options to update or regenerate the code base to make it more modern and safe.

Our Gradle plugin is mainly a wrapper around our middleware build tool (SCADE Build Tool), which we use in combination with our Android toolchain. Over the years, we have implemented many Android-specific tasks inside the tool, and for better integration into the Android world, we started to wrap it inside a Gradle plugin. But as we need to add more and more Gradle-specific parts, and also because we are planning to add support for the Swift Android SDK, it would definitely make sense to collaborate on this topic.

We are happy to collaborate and look forward to working together on these exciting developments.

4 Likes

Seems I totally left a reply on draft here… :face_with_peeking_eye: Sorry for that, better late than never I guess:

Yes, available through swift-java wrap-java and through the build plugins.

Here’s an example that declares that it’s using the Java BigInteger type, and the plugin generates the necessary Swift code to do so: https://github.com/swiftlang/swift-java/blob/main/Samples/JavaProbablyPrime/Sources/JavaProbablyPrime/

There’s a few other examples, like one which even downloads java dependencies and then wraps them etc. We should do more docs about this workflow, but yes it is supported and works in basic cases already.

Indeed! I’d love to collaborate on those; Perhaps the best time will be once we have the offcial Android SDK and can start developing the gradle plugin and have CI using the SDK on the swiftlang repos etc…

More than happy to hear your use-cases and drive it from there.

Thanks again and let’s keep in touch :slight_smile: