iOS + Android OF project considerations - GPS location, gesture recognition, multiple screens


I’m starting up a new project and I chose openFrameworks for the job. It’s going to be a cross platform app (iOS + Android) and I wanted to share my experience thus far.

  1. I downloaded the release packages for iOS and Android and consolidated them until I had one code repository that contains an xcodeproj AND eclipse project, with all necessary files + common cpp files for both. I’m experienced with cross platform development (using cocos-2dx) so it wasn’t too hard, but still not exactly trivial. I think it’s a good example to be shared publicly and build upon since multi platform projects are becoming more and more popular. I think there should be a unified Android/iOS package instead of separate ones, with examples for both, some of them sharing the same cpp code.

  2. My app will require a location. I used ofxiOSCoreLocation and ofxAndroidGPS. Naturally, I wanted the same cpp code to get the location regardless of the running OS, so I created a layer of abstraction that I think could be useful. I also think that this pattern should be embraced on many add ons that offer similar functionality for iOS and Android. There shouldn’t be a separate interface for each OS. That defeats the purpose of a cross platform framework.

  3. My next endeavour is having gesture recognition running cross platform. I see there’s a ofxGestureRecognizer that someone made for iOS that wraps up the objective C part but I haven’t checked it out yet. I haven’t found any existing code for android so I intend to develop it myself. Same goes here, I intend to consolidate the interface so that is can be used on both OS’s seamlessly. I would be happy to contribute that code to OF.

  4. Lastly, my project is not solely open GL stuff. It contains native iOS/android UI. It also contains multiple screens, with different layouts, each one should be a different “OF app”. In iOS, the iOSNativeExample was very helpful, to understand how to make iOS the boss, and not OF, using ofxiOSViewController->initWithFrame. But for Android, I don’t see a simple solution. Basically, I want to have multiple activities inheriting from OFActivity. Now, as I see it, inside OFAndroid there are two places that needs intervention in order to do that. One is:

    View view = ofActivity.getLayoutInflater().inflate(layout.getField(“main_layout”).getInt(null),null);

I will need to pass the name of the layout I want, so it won’t be hardcoded to “main_layout”.

The second location is:


that passes over jni to the cpp side. I will need to pass over which “OF app” I want to run there. It doesn’t seem that I will be able to do those changes in inheritance, and it looks like I’ll need to splice things directly in the massive OFAndroid class.

And that’s assuming that the life cycle of these objects are designed to be destructed correctly when passing between screens.

That’s all I’ve got for now. I’ll be happy to hear some feedback and advice on those directions from some OF experts, and if anyone else is in need of (or already have) solutions to those problems.


Tal Lavi

you are right that there’s several things that need to be unified between the iOS and android releases, i’m not sure if a common download is a good idea since iOS can only run in osx, but unifying some addons like gps… is definitely needed so if you come up with wrappers or even common addons that could be useful or in general want to contribute to that it’ll be super useful.

about using multiple activities, it’s really not well supported in android yet, as you have noticed OFAndroid needs some refactoring since it’s huge and that would probably make it easier to add features like several activities… the main problem is that the integration of the life cycle between java and native code is a real pain for only one activity so doing it for several will really need some thought and time. again if you come up with something related it will also be really useful.

if you want to work in any of this issues feel free to contact me directly for help or if you have any doubt about the current structure

Hi @tallavi
So you have your consolidated oF code repository available on public git?
I’m about to start a cross platform endeavour, so I’d be interested to see how you’ve approached this.
Many thanks

Hey @Miles,

No, I’m afraid that my consolidated OF project is embedded inside my private project code, and I haven’t made a template out of it or something, but it’s quite easy to recreate:

Start with the master branch of OF, it contains the binaries needed for both Android and iOS. Now take an android example, and copy over the xcodeproj file and other dependent files until you are able to compile in xCode too. It didn’t take me long to get it working that way.

Regarding my related side endevours, those are freely available on github:

I have there a cross platform gesture recognizer and gps addons that you can use if you need. The gestures should work on any touch enabled version of OF. The GPS is for iOS and Android. Each addon has a single interface that abstracts the specific os implementation.

If you have any more questions, don’t hesitate to reach me here or with a message.

Good luck,


Hei, are there any news on this? On how-to create a cross-platform app for android and iphone?
This thread died in 2015…

Not much has changed, most of the code you can write with OF is portable for all platforms (third party addons are definitely a wild card here). If you have the build system working for each platform you will be able to use the same code to some degree. There are comprehensive setup instructions for iOS and Android on the openframeworks website - a great place to start. Downloading OF from GitHub will mean you have all platforms in one OF “install” and you can even use the same project folder and source files if it is appropriate.
But if you are imagining a fully featured native looking app on iOS and Android it will take a lot more specific work for each platform.

I had a cross platform 5 years ago based on OF 0.8. I started by creating an ios and android projects and merging them into a single project so that the c++ src would be the same, but it will have both ios and android boiler plate. Then I wrote all the opengl UI in the cpp side, plus all the business logic code so I don’t have to port between the OSs, and left only non-opengl code in java or objective c respectively.

Regarding plugins, most of them are specific for one OS, for example, separate gesture detector plug in for iOS and Android, separate GPS plugins, etc. It’s easy to separate c++ between OSs, there are two different methods:

  1. using ifdefs, with different defines when building for ios or android
  2. A single header file, for example, MyClass.h, but different cpp files, for the different OSs: (Objective C++) and MyClassImplAndroid.cpp, each one with the platform specific code. The iOS one calling some objective C classes and APIs, the Android one using JNI to go back to the java and use some Android APIs. Also note that some Android functionality comes exposed to cpp out of the box, for example GPS.

Hope it helps.