ofxQCAR-Android : OF overwrites custom Android.mk when trying to add external library

Hi all,

For the last weeks, I’ve been trying to make @julapy’s ofxQCAR work in OFAndroid.

i’ve translated the add-on (which was an objective-c/cpp mix) and adapted to JNI/java so far and was trying to make it work.

To do so, some libraries needs to be called from OF (in this case, libQCAR.so , provided by vuforia)

I wanted to include this libraries through Android.mk in order to compile them in a OF project.

When trying to do so, Android.mk is overwrited and doesn’t include the contents in the project. I’ve been checking the info here: http://ofxaddons.com/howto/ and can’t find the way to compile the external libraries into OF.

Might be something related with the default project makefile but i can’t figure it out.

Could anyone help with this? Any ideas?

Thanks in advanced!

I think oF does not use Android.mk but it has its own set of makefiles under the subdirectories of OF_DIR/libs/openFrameworksCompiled/project directory.

Oh,

i missed that. I’ll check, try to compile and post results.

thks!

yes Android.mk is generated by the OF makefiles, if you want to include a library you need to edit config.make

also you can create a addon_config.mk file inside the addon folder to configure which files, libraries… it includes when added to a project, you can check the ofxOpenCv addon which has a config file

I see ofxOpenCv in Android works like this:

android/armeabi-v7a:
ADDON_LIBS += libs/opencv/lib/android/armeabi-v7a/libopencv_legacy.a

Although, in our case, we’re trying to add shared ( “.so” ) libraries which are prebuilded.

Do you think it might compile too?

thks!

I confirm it has compiled.

thanks a lot!

:smiley:

great, in the case of dynamic libraries, you’ll need to add it to the project to, i think you need to copy them in the libs folder inside the corresponding architecture folder

Not “libs” but I think it should be “lib” folder. libs folder is generating automatically by Android. He needs to put the SO file under Android_Project/lib/{target_archabi}/

And Johan you probably need also to add the loader codeline into the OFAndroid.java, to the top of loading libraries.

try {
    System.loadLibrary("yourlibname");
    ...
    System.loadLibrary("OFAndroidApp");
} catch (Thowable e) {
    ....
}

i’m think it’s the libs folder, no matter if it’s the app’s library or any other additional one: http://rschilling.wordpress.com/2013/03/22/adding-shared-libraries-to-your-android-ndk-build-insanity/

also not sure how this particular api works but if you are linking the library from c++ probably you don’t need to load it from java since you are not going to use it from java

Hei,

that makes sense.

@Rancs in this case, i think the library isn’t needed inside JAVA cause we already have a JAR we can call.

Android overwrite libs folder.

For example you prepare lib/armeabi and lib/armeabi-v7a with including corresponding versions of your library. And you add APP_ABI=armeabi (or whatever you target) line into the Application.mk.

Then Android reads the target archabi from Application.mk, it takes the corresponding subfolder of lib and it generates libs folder. And it puts the generated libs folder inside the apk. Then you load the library in runtime.

In the general system of Android, you need to load each library one by one. Otherwise you can not use it even if it exists inside the apk. Forget the blog post, I know the general system better then its writer.

JAR to load the library? Ok, if there will be a problem, then we can talk again.

@JohanSebastian Well, finally, I think the JAR file should probably be for Java side usage, but you are in the native side. So probably you need to load the library yourself. Anyway let’s wait the coding stage.

i think you are used to ndk-build but we don’t use that, instead the OF makefile system is creating the libraries in libs/arch/. Also Application.mk is generated by the makefiles and overwritten every time so it won’t work the way it usually does in android.

If you clean the project libs will probably overwritten and you’ll need to copy the library again but apart from that libraries should go in libs

@arturo Ok I tested it, he needs to put it inside the libs folder. Sorry. This is slightly different then the general way.

Anyway, he still needs to load the library, if his jar file is useless in native side :)))))

@JohanSebastian Did you manage to port ofxQCARto Android finally? If so, I would be really interested to try it!

I’m trying to compile ofxQCAR for Android as well… @JohanSebastian is this library recompilation the only thing needed for the addon to work?