Askam Eyra Askam Eyra - 4 years ago 287
Android Question

how to make a cordova android plugin using external non-builded lib (OpenCV)

I'm trying to create a cordova plugin to use OpenCV on android and iOS.
I am for the moment at the android part.

I downloaded the OpenCV android package, and create a test application with android. That work, so I just need to put that in the plugin.
But I have absolutly no idea about how to import the OpenCV library in the plugin.

Someone know how to do that ?

Thanks in advance

Answer Source

Have you written a cordova plugin in the past? If not, this is probably not the easiest place to start (if you haven't start with the plugin guide from the Cordova team.).

Including JNI (native code) in Android in Cordova plugins is a bit of black art, but you are lucky that someone has gone there before (and abandoned) a Cordova OpenCV plugin for Android. Study that, and then for iOS it is a lot easier, since you can CocoaPods or just include the library and don't have to worry about C/Java bridge. If all of this is making your head hurt and you have no idea what JNI is then you might want to farm out the writing of this kind of plugin to someone else.


I was going to add this in a comment but it was too long:

An apk is a complete App and not a need to include the various .so files (shared objects) for openCV. If you want to learn how to link a C++ file into an Android app (first step of creating a Cordova Plugin with JNI check out this tutorial. However, since half the work has already been done for you, what I would do is just download the OpenCV Plugin into a directory and then

cordova plugin install

and fix what you need (if you get everything working, think about forking the original project and contribute back to the community :) ).

As stated the plugin for iOS will be similar to other IOS plugins, maybe look at the cordova-cocoapods project, the other cordova-cocoapods project and the OpenCV CocoaPod.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download