"jni" folder not found



When I start programming with OpenCV and Android NDK, I encountered an error with not found ‘jni’ folder in project which is critical to creation of application.


So I found my own way to solve that problem.

First of all you have to create a folder called 'jni'



Then you have to create an external tool configuration to configure jni. To do that you have to small arrow button external tool button in short cut bar.

Click the down arrow and select ‘External tool configuration’, you will end up window like below.


Press select Program and press new in upper corner which calls ‘New launch configuration’


Provide any appropriate name you like for ‘Name’. In ‘Location’, you must give your ndk-build file. So for that first select ‘Browse File System’


And then browse to your android ndk folder and select ndk-build file



Then for your ‘Working Directory’, you have to give your jni folder. So for that first you select ‘Browse Workspace’


And select your 'jni' folder in working project 

Then press ’Run’. Sometimes this will display some error message ignore that message. Even though we have create jni configuration but it still show the error that shows in console in start because there is no file that ‘jni’  folder and we have to configure them.

So, first thing we are going to do is create ‘Android.mk’. Go ahead and create ‘Android.mk’ file in jni folder.


Add something like this code, if you want more about Android.mk file go to your android ndk foler and there you will find folder called ‘docs’ in there you will able to find HTML file call ANDROID-MK, in that document, you are able to find details about your Android.mk file

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog 


LOCAL_MODULE    := ndksetup
LOCAL_SRC_FILES := native.cpp



include $(BUILD_SHARED_LIBRARY)


But we are not still finished. Then we are going to create our native.cpp without it console shows a message like this

  
So to fix this, we are creating file called ‘native.cpp’


In that file you have to write your OpenCV codes according to your program. (Writing code for native.cpp file is out of this post scope)

There is an additional file called ‘Application.mk’ but it is optional file to create.

Eventually, if you will see a message like this below in your console

Now, you are up and running with android ndk in you android app. 

Installing OpenCV manger to Android emulator

When you start to programming with OpenCV with android and if you don't have any android device to emulate those programs, you definitely have to use the Android emulator.

But the thing is you can’t run your programs in your emulator because it gives an error like below, 


So if you try to install it by just clicking install, it won’t because you don’t have direct access to Google Play Store, so you have to manually install to your emulator.




So let get start to install OpenCV manager to your android emulator.

First thing first, you have to download OpenCV manager apk file via this link given below 
Link to OpenCV manger APK file

and move/copy it’s into your platform-tool folder in sdk folder where you have copied your android SDK folder. Mine is like this “C:\adt\sdk\platform-tools”



Then next step, you have start you preferred emulator and wait until its get started and shows android wallpaper.

Then start you command promote whatever the way prefer to invoke it.

Then go to “platform-tool” folder with using commands in command prompt and enter following code segment

adb install {OpenCV manger package name}.apk

And wait a little moment until it shows “Success” message

Yap, you did it, now if you got to your menu in android emulator it will show the OpenCV manger icon.




Now you can run any of your OpenCV android application in your emulator.