Advertisement

Mobile dev - C++ only or switch to Java / Swift

Started by June 02, 2019 04:40 PM
6 comments, last by stratusfer 5 years, 3 months ago

Hi everybody,

I'd like to give myself another chance, and try again to go for mobile app development.

I have years of experience in C++, so I'd like to leverage it in some way. 

I would like to target Android first, and maybe iOS later on. 

My question is: should a go all-in with C++ only (including UI), write everything in Java (Swift) or maybe just the UI in the native language and the rest in C++.

Any kind of suggestion is much appreciated, also on how to start / approach this world :)

 

Cheers

 

[Edit] I've heard also about xamarin and other options. How about them for UI and C++ for the rest?

 

I'm still working my way into Android development myself, so this isn't authoritative or anything, but I'd recommend the 'mixed' approach, that is, write as much as you can or want to in C/C++, but use one of the available 'host' languages for the basic framework.

On iOS, Objective-C(++) is arguably easier to integrate with C++, but I'd probably go with Swift. It's up to you of course, but Swift has more momentum now, I think, and is arguably easier to work with in some ways.

On Android, you can use Java of course, but I'd recommend looking into Kotlin as well, as it (arguably at least) has some advantages over Java.

My understanding is that on Android you can in fact write apps entirely in C/C++, with no Java/Kotlin/whatever. I've looked into this approach, and my initial impression is that the added difficulty of doing it this way probably isn't worth the gains. YMMV though. (For what it's worth, the well-known open-source game frameworks I've looked at that support Android use the 'mixed' approach.)

Lastly, I'll state what's probably obvious, which is that even under the best of circumstances, implementing everything from scratch can be nontrivial, and using any of the various existing frameworks that are available would probably save considerable time and effort. If you do want to go the bespoke route though, based on my experience so far at least, I'd say the 'mixed' approach may offer the easiest path forward.

Advertisement

Thank you very much for your advice.  

Quote

(For what it's worth, the well-known open-source game frameworks I've looked at that support Android use the 'mixed' approach.)

Interesting, which one would you suggest? 

I've heard also about Kotlin multiplatform, but I don't think it's stable yet

2 hours ago, stratusfer said:

Interesting, which one would you suggest?

I'm not sure I have a suggestion per se, but here are some possibilities:

There's Unity, which is popular and has a lot of support. Typically with Unity you'd be using C# (although there may be other options available, depending).

Cocos2d and Godot are both open-source, and I think both are fairly popular. I think there are different versions of Cocos2d that allow you to use different languages; Cocos2d-x, for example, is geared towards C++ if I'm not mistaken. I think Godot uses a custom scripting language (hopefully someone will correct me if I've got that wrong). I'm not sure if it exposes other options, but it should be easy enough to find out.

Of course there are many other frameworks out there - I think someone even posted about a new fairly comprehensive framework of their own creation here on the forums recently. In any case, there are quite a few options available if you don't want to do it all yourself.

11 hours ago, stratusfer said:

UI in the native language and the rest in C++.

Are you making games? If so, yes, exactly this. For Android, make JNI calls into Java from C++ to show UI elements. You'll need to use handlers to keep UI on the UI thread (if your C++ runs on the GL thread). For iOS, it's pretty easy to mix Objective C and C++ (as Objective C++). Mixing with Swift is harder (I haven't tried, but I think it requires an Objective C++ layer). I'm currently doing this and there is a problem of Apple phasing out OpenGL and everything switching to Vulkan and Metal instead. I'm probably going to end up with a separate set of Metal renderers for iOS, or, if I switch to Vulkan, I may end up using MoltenVK.

If you're not making games, you may be better off doing Java and Swift, since you'be interacting with the Android and iOS system API's more and they're very different and the libraries you may need are usually written for each OS specifically.

8 hours ago, VoxycDev said:

Are you making games? If so, yes, exactly this. For Android, make JNI calls into Java from C++ to show UI elements. You'll need to use handlers to keep UI on the UI thread (if your C++ runs on the GL thread). For iOS, it's pretty easy to mix Objective C and C++ (as Objective C++). Mixing with Swift is harder (I haven't tried, but I think it requires an Objective C++ layer). I'm currently doing this and there is a problem of Apple phasing out OpenGL and everything switching to Vulkan and Metal instead. I'm probably going to end up with a separate set of Metal renderers for iOS, or, if I switch to Vulkan, I may end up using MoltenVK.

If you're not making games, you may be better off doing Java and Swift, since you'be interacting with the Android and iOS system API's more and they're very different and the libraries you may need are usually written for each OS specifically.

Just a couple quick comments. It might be worth mentioning again that you can use Kotlin rather than Java on Android if you prefer. Also, you don't need an Objective-C layer to mix Swift and C++ (although using Objective-C(++) can be more straightforward, as you note).

Advertisement

Cheers guys!

Yep, I'd like to do some games. 

A C++ only option could be Qt, but I'm not sure how good it is for videogames.

Another alternative I've in mind is still using C++ for the core part and using Flutter for UI.

Not sure about how easy is mix C++ and Dart, but it can be an option. What do you guys think?

 

This topic is closed to new replies.

Advertisement