3 ms·
How are you using Swift on Android?
by untog 6y ago
How are you using Swift on Android?
- deleted 6y ago[deleted]
- FlyingSnake 6y agoThere are several ways to use Swift on Android. It's basically Swift <-> C interface <-JNI-> Java. The following links could be a good starting point for Swift on Android. [^1] https://github.com/apple/swift/blob/main/docs/Android.md https://github.com/apple/swift/blob/main/docs/Android.md [^2] https://github.com/readdle/swift-android-toolchain https://github.com/readdle/swift-android-toolchain
- anupamchugh 6y agoWould you really use a JNI bridge and end up with a possibly heavier codebase? Swift for Android isn't officially supported by Android yet. I'd rather use Kotlin Multiplatform instead.
- untog 6y agoSounds messy. You’d have to manually define the JNI calls on both sides if I’m reading correctly? Good to know it’s possible though. Just maybe with more tooling...
- liuliu 6y agoJNI is so expensive when cross the language barrier, you have to be conscious to constantly minimize your API exposure. This may be helpful in long-term, but not helpful for onboarding purposes. On the other hand, if you can lower Kotlin to native code, it may be more natural to interact with (of course, there are still these nonsense of Java's default UTF-16 string <-> Swift's native UTF-8 string conversion). Interoperability between high level languages are just hard. I am skeptical of either way, but I can see how it is more appealing to go from Kotlin to Swift direction. On the other hand, data modeling and high-level data transformation doesn't require all language features. It is possible to do such with a limited DSL that supports product / sum types, some filter / map / flatmap / zip, and boom, you now have your view models for UI rendering. As long as we've made up our mind on string UTF-16 / 8 or have some performant library to do lazy transformation on these. We can go a long way on standardize business logic cross iOS / Android platform.
- pjmlp 6y agoJava is replacing JNI with Panama efforts, but don't expect that to come to Android. In fact, in 10 years Google has never made available their internal tools that simplify JNI integration, leaving the community on their own to create our tools.
- wdb 6y agoI am using the Elements compiler (supports Swift, Go, Visual Basic, C#, Java and Object Pascal) that allows sharing business logic and write UI code separately in the appropriate platform's tool.