4 ms·
I've been using C++ to share code between iOS and Android for years and have come to the same conclusion. I developed the C++ code on desktop operating systems
by jdswain 7y ago
I've been using C++ to share code between iOS and Android for years and have come to the same conclusion. I developed the C++ code on desktop operating systems which was easier to debug, but once you move it to mobile then the debugging gets a lot harder (on Android at least).
The overhead of the JNI interface is quite a lot of work too. Luckily I had a UML model that I generated the interfaces out of, so adding JNI was just a matter of templating this out of the UML, but it was still quite a bit of work.
On iOS the situation has gotten worse in that the interface between Swift and C++ has to go through C, so if you are using C++ you need a special interface layer, which is almost like the JNI situation on Android.
So you have the trade-off of on one hand having two code bases (Swift, Kotlin) and the associated headache of keeping them in sync, versus the extra work of maintaining the C++ interface layers and testing and debugging on each platform. In the end I now believe that it is better to work with the platform native development tools rather than trying to share C++.
As far as finding developers goes, because of the rarity of using C++ on mobile there will not be a lot of developers with this experience. I work remotely and have found that any remote C++ work is very rare, Swift and Kotlin are a lot easier to find work with (it's still more difficult that you would think to get remote work of any type).
- therockhead 7y ago>On iOS the situation has gotten worse in that the interface between Swift and C++ has to go through C, so if you are using C++ you need a special interface layer, which is almost like the JNI situation on Android. I’m curious why you don’t add an Objective c layer for C++ interoperability, I’ve done this in the past and it works a great.
- jdswain 7y agoIt's mainly because I'm trying to write everything in Swift now rather than Objective-C. I still think Objective-C is a great language, but Swift is the future of iOS development. It was easier in Objective-C as you could just rename your code file with an extension .mm rather than .m and that made it Objective-C++ and then you could import your C++ headers and use your library as you should. With Swift you don't have that option, and even the interface to C is more difficult. Even with Objective-C there is still some work in converting data formats (NSString to std::string etc.) and you need to be careful of C++ exceptions and NSException.