Openframework ofAndroid addon

I am new to openframeworks. I using OF for android. At the moment my goal is to understand the dynamics of the framework. For example how OF is interacting with Android. I understand addon.make file contains loaded addons that are loaded and used in native code. However, for android examples I found one java based project called ofAndroidLib. Can you please explain to be what is the purpose of that project and how that is interacting with android and native source files. Sorry if that is very generic but as I mention I am newbie who is really looking forward to dig deep into framework. Thanks

Android is an operating system and he provides his own libraries in the Java programming language (commonly referred as “Java side”). But openFrameworks is written in C++ (commonly referred as “Native side”)

Like each software openFrameworks needs to interact with some operating system libraries. The methods and the callbacks of the Android libraries provided in Java side should be somehow transferred to the Native side. And the methods and the callbacks of the Native side should be somehow transferred to the Java side. In the Java world, these two sided transfers are conducted by Java Native Interface (JNI). JNI system has methods both in Java side and in Native side to perform the data transfers.

ofxAndroid is one of the official addons of the openFrameworks. He is a JNI implementation who provides the data transfers between the Java side and Native side. Like each major JNI implementation, he has some methods in the Java side and some methods in the Native side to be able to perform the transfer jobs.

ofAndroidLib is the Java part of the ofxAndroid, where the necessary Java methods are implemented. Thanks to ofAndroidLib classes and methods, openFrameworks can interact with Java libraries of the Android operating system.

Thanks it help alot. One more thing is there any documentation that explains how ofandroid plugin is implemented. Specially workflow of java side functions and native side functions.

Unfortunately there is not a workflow documentation. But generally;

  1. Android initializes your project’s Activity (for example Activity of the androidEmptyExample).
  2. Your Activity initializes ofAndroidLib’s class.
  3. initializes the native openFrameworks system.
  4. openFrameworks system initializes your native main.cpp class.
  5. main.cpp initializes your native ofApp.cpp class

And the flow for the further usage is generally like that:

If there is a callback from Android, such as keydown, pause, etc…

  1. Android invokes the related method of your project’s Activity
  2. Your Activity invokes’s related method
  3. invokes your ofApp.cpp’s related method

If you need to use Android’s some Java spesific libraries such as VideoPlayer, SoundPlayer, etc…

  1. Your native ofApp.cpp invokes ofxAndroid’s native side
  2. ofxAndroid’s native side invokes ofAndroidLib (ofxAndroid’s Java side)
  3. ofAndroidLib invokes Android’s related library.

If you try to get some data/variable from Android’s some Java library such as isOnline(), getVolume(), etc…

  1. Your native ofApp.cpp invokes ofxAndroid’s native side
  2. ofxAndroid’s native side invokes ofAndroidLib
  3. ofAndroidLib invokes Android’s related library and get the response
  4. ofxAndroid’s native side get the response from ofAndroidLib
  5. Your ofApp.cpp get the response from ofxAndroid’s native side.
1 Like