Search code examples
androidopencvjava-native-interfacenative

Running C/C++ code using OpenCV in android


I don't know whether i make sense or not. But just wanted to now that can i run the c/c++ code in android without the need of writing JNI wrapper or using Native Activity way?

I mean, I am having a simple C++ Template Matching code which contains main function and I use to run it using g++ in terminal.

Now I want this Template Matching code to be run in android usng NDK. Is there any way? I have googled a lot but all they is to either use JNI wrapper or use SWIG which makes JNI wrapper, but can't actually get into any of them. I need more simpler solution.


Solution

  • If you have a rooted phone, you can compile and run programs as on any linux machine, from the adb shell.

    However, that requires a bit of knowledge about Linux.

    So, to start:

    • Root your phone (force it to give you admin privileges). That is easy for developer phones/boards, and a kill for regular phones bought at a shop downstreet.

    • compile your app for android and run it from adb as you would do from a linux shell.

    Here is a more detailed answer on the matter

    How to compile C into an executable binary file and run it in Android from Android Shell?