logoalt Hacker News

nicoburnslast Sunday at 12:37 AM3 repliesview on HN

Interestinggg. How does binding Java/Kotlin code into Swift work?

(we're trying to do something very similar with Rust instead of Swift)


Replies

mihaellast Sunday at 2:20 AM

It works primarily through the jni-kit library, which handles JNI bindings between Swift and Java/Kotlin. You can check out the full docs here: https://docs.swifdroid.com/jni-kit/

On top of that, the IDE also auto-generates required Java/Kotlin classes on the fly, for example, for Activities.

satvikpendemlast Sunday at 4:20 AM

For Dioxus?

I was looking into something similar, on Flutter it uses FFIgen and JNIgen, might be something to look into on the Rust side. From what I've seen, it's quite difficult from pure Kotlin to Rust, as I was looking for the equivalent of the flutter_rust_bridge package when experimenting with Compose Multiplatform, as I have some crates I need to use, but I ultimately gave up because it was not straightforward at all.

lukehlast Sunday at 9:14 AM

Another approach is swift-java, which uses Swift macros and also supports Panama.

https://github.com/swiftlang/swift-java

show 1 reply