Cross-platform (iOS/Android) Mobile App development using C++
At AmigoCloud, we use tons of C++ & OpenGL for our Mapping applications.
Funny enough, when I talk to tech-people about our startup and tell them that we have a cross-platform framework, the first words that come out of their mouth is “HTML5”. Although we do use HTML5 for some of our components (a topic for another day), they always end up looking surprised when I tell them that 90% of the code is C++ (the other 10% being platform specific GUI + glue code).
Yes. Actually, it gets better.
The truth is that the same core client C++ code runs completely fine on OSX, Android, iOS, Windows, Linux, FreeBSD and possibly other platforms that we have not bothered to attempt.
C++ is an awesome versatile language with tons of libraries that, when carefully chosen, will make your life easier because they work completely fine on different platforms.
Local storage? How about sqlite.
UTF16 support? Know about ICU (we use something different, but I had to mention it).
You can have it all (mostly).
By now you may be asking yourself, “I know how to write C++ and use those libraries, but how do I consume them in, say, Android and iOS?”.
For iOS, you need to be aware that there is such thing as Objective C++ and this makes consuming C++ from Objective C trivial. There are several excellent articles in the net that describe how to do this.
For Android, you need to be aware that there is such thing as a native sdk (aka android ndk). Again, there are several good tutorials online that explain the process.
In our case, the GUI code is (intentionally) platform-specific because we want to get the native control feel for each phone that we target. We also have a small set of wrappers for phone specific things like access to the phone sensors (a topic for another post).
Is it all as awesome as it sounds?
Sadly - no.
IMHO, there is a huge downside to it all: the build completely sucks.
Think about how many targets you have. Just in iOS, you can have x86, armv6, armv7 depending if you are running this on the emulator, or different iPhones. Every single dependency that you add will need to be compiled for that target. Then think about debug + release. Yuck!
So what to do about this?
At AmigoCloud, we use a custom build system for this. Nevertheless, when I was looking into this some months back, I stumbled upon several great scripts to take care of this process.
CMOSS itself is simple and works. Perhaps, if there is enough interest, I’ll write a small “Hello World” app that uses CMOSS to build both iOS and Android apps.