4 ms·
Question for mobile devs - how viable is to share code betweeen native android and IOS apps? IE, all the user interface is done natively, but you share business
by LAC-Tech 4y ago
Question for mobile devs - how viable is to share code betweeen native android and IOS apps? IE, all the user interface is done natively, but you share business rules, and maybe even an abstract view layer with names of fields, actions etc.
Would you have to write it all in C, as that's the lowest common denominator for stuff that can be used in both swift and kotlin? Or are there other alternatives?
- Vt71fcAqt7 4y agoFlutter[0] lets you share the whole UI and really only requires per-system changes for thing like file system management. [0]https://flutter.dev/ https://flutter.dev/
- LAC-Tech 4y agoRight but say you wanted separate UIs written in the native language for that platform. Again - not a mobile dev - but my spidey senses tingle when I see "cross platform UI". Feels like it won't go well, that different platforms have different conventions, that the abstraction layer will leak like a sieve, etc.
- Vt71fcAqt7 4y agoAs I didn't make it clear, my response was to "Or are there other alternatives?" rather than to your main question.
- secretsatan 4y agoCpp libs can mostly be used and it’s the strategy we use, the main worry is trying to avoid massive sizes with dependencies up the yazoo in some of them. I’ll speak from the swift side, it’s improving a lot, but we’re still in a bit of a transitional phase. With a swift package, you can include cpp libraries but still need an obj-c bridging layer, but afaik swift is becoming better at interoperability, but we maintain a few versions behind swift bleeding edge. Android are also able to add their own stuff to the repos to make it work. So we basically have a mobile repo that can work for ios and android, pulling in cpp binaries as submodules
- K0nserv 4y agoI think Rust is one of the most promising languages for such a shared layer. Can also be used on the web via WASM. This enables native UI with shared business logic. Kotlin Native is another option that still allows native UI on the iOS side.
- LAC-Tech 4y agoPromising - so not there yet in this capacity?
- K0nserv 4y agoNo, I meant more as in haven’t tried it myself. Plenty of folks have done similar things with C and C++, I’m not sure if anyone has done it with Rust yet. Certainly more difficult than Flutter or RN, but if truly native UI is a goal I think it, along with Kotlin Multiplatform, are the best options
- david_allison 4y agoIt's there in this capacity (sharing a common rust backend between Desktop/Android/iOS) https://github.com/ankidroid/Anki-Android-Backend https://github.com/ankidroid/Anki-Android-Backend => https://github.com/ankidroid/anki/tree/9f2920a063e9177cce082faa8aae4e78ea1751dd/rslib https://github.com/ankidroid/anki/tree/9f2920a063e9177cce082...
- danielrhodes 4y agoYou can use C++/C to do this but depending on what you're doing it probably won't save you much time. You could also use JS to share code since both platforms have JS interpreters you can run arbitrary code in - but the ergonomics of this would likely be sup-optimal. For most apps, the vast majority of the work in mobile is the front-end - so sharing code this way would just end up being a headache.
- LAC-Tech 4y agoIs mobile dev a bit like frontend web dev, where people really struggle to separate UI from business logic? Frontend web dev essentially had no concept of architecture, it was all code behind IME.
- danielrhodes 4y agoMore or less, yes. Because you have more opportunity to maintain state locally on a mobile app (which isn't done as much in browsers), you will see more business logic. But it's largely very similar to web dev. Again though: depends on what you're building and how much you need a remote backend.
- secretsatan 4y agoThis reply has been bugging me. No, though i’ll admit it can be easy to get sucked into, bit that’s true for any platform, there are plenty of strategies to avoid this, mvc with uikit and swiftui further improves. Just setting up test targets can mitigate this kind of thinking
- occz 4y agoIf you want to do code sharing on mobile between android and iOS, Kotlin Native is probably the most viable technology on the market. Doing some MVVM-style solution where you share the model and view-model layers is probably the type of architecture you would want to go with, having both view layers merely subscribing to an abstract description of the view state living in the view-model and sending up commands to manipulate the view state. As for being viable - it's certainly doable, but the technology is still a bit rough around the edges, and it's not at all certain that it's going to be worth the effort.