Ask HN: Using C or C++ for parallel Android and iOS dev.

13 points by jbm ↗ HN
I have read quite a few comments in the past about people using C or C++ as the backend to their Android / iOS projects, with Objective C / Java being used for the front end interface code. Unfortunately, I've never seen a project like this open sourced, and I am sure I will fall into a whole set of pitfalls if I begin from scratch.

Are there any books or example source for even trivial applications that actually use C or C++ from the backend work?

(I am aware that you can use C# through mono touch, but I try to avoid the .NET technologies outside of work)

4 comments

[ 3.2 ms ] story [ 21.7 ms ] thread
I think you want to have a good, close look at MOAI:

http://getmoai.com/

Its a C/C++ based engine that includes a Lua VM, wherein you write your real app code. The engine runs on Android/iOS/OSX/Linux/Windows. There is a 'host' element to the MOAI project, where native stuff happens for each environment, and the host itself ends up running the VM to interpret the Lua code needed.

Another approach is with games, where a 3D engine is built in C++, with the NDK (on Android) used to interface with a 'wrapper' app that gets the library loaded and in use. I used this approach with a 3d game which uses the same C++ code for Android/iOS clients .. it was a fair bit of work, but the result is that we can do the game logic in C++ and forget about the platform-specific stuff.

I know of two, but haven't used either so far:

1. Cocos2dx (open-source)

2. Marmalade (commercial, you don't even need a mac, can prepare iOS binaries on a Windows machine)

I have used all 3 of them. Here are my impressions:

-Marmalade ( Airplay when I used it ) is the most professional framework. I have never found a bug and also the number of documented bugs is very low. The framework is supported on many platforms ( IOS,Android,Ipad,Bata, Nokia,Windows CE, [Blackberry also if i remember well]and also consoles if you are willing to spend some more big bucks). It is possible to develop on windows using Visual Studio and one can obtain installations packages (ipa,apk and so on) with a single click without ever leaving windows. The framework is pretty low level so you are going to write more code using a more robust platform. Documentation is very complete. The framework has also some tools for asset packaging, fonts, etc. Both 2d and 3d apps are supported. There is also a basic GUI engine that is resolution/device indipendent ( with a basic GUI designer ).

- Moai is the easiest framework to use if you are willing to use LUA as your main development language. However I have found it a little bit counterintuitive if you want primarly to do C++ development. Documentation is sufficient. 2D games only. MOAI license put some constraint on apps that store information on the internet/cloud and/or have multiplayer support

- Cocos2d-x is a community effort. I found it more convenient for pure C++ development than Moai. Cocos2d-x API is modeled after Objective-C and sometimes uses Obj-C idioms instead of C++ idioms. While this considerably ease the porting from pure Obj-C Cocos2d app it may not be to everyone taste especially for experienced C++ developers. Cocos2d-x community is bigger than Moai's. While Cocos2d community is very activy on further developing cocos2d-x and fixing bugs Moia community is more active on the development of extensions and new features. 2d games only. Support for lua even if I have not used it.Almost no documentation. However the API is a 1 to 1 mapping of Cocos2d for which there is an abudance of information.

At the end these are my suggestions:

- You are a big studio-> go for Marmelade.Documentation is better, you have professional support and probably the framework is the most stable and certainly the more mature.

- You are a small/indie studio and like to code in Lua-> go for MOAI.

-You are a small/indie studio and prefer pure C++ coding and not be constrained in any way by the license-> go for Cocos2d-x.

After using Airplay when it was free now I am using cocos2d-x for my new projects.

Just to clarify your comment - the Moai engine supports isometric (2.5D) and 3D functions for effects. Shadowrun Returns, a 2.5D title, is being developed with Moai. See http://getmoai.com/blog/thinking-isometric.html for an overview.

There is no license restriction on Moai as noted. It's a standard CPAL license, approved by the Open Source Initiative. CPAL itself is a derivative of the Mozilla license. http://getmoai.com/moai-faqs.html