Hacker News new | ask | show | jobs
by nicoburns 168 days ago
Interestinggg. How does binding Java/Kotlin code into Swift work?

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

3 comments

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.

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.

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

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

Panama will probably never make it to Android, given Google's behaviour on updating Java support.