Reprint marked Source: http://blog.csdn.net/ikerpeng/article/details/45393223
To resolve the issue:
Android code calls excellent C + + code and efficiently implements the required functionality.
The overall idea:
1. Complete your Android code;
2. Generate the C + + code. So;
3. Place the. So library in the Android Libs folder;
4. In the Android code, define the interface function to be called and import the library.
The specific operation:
1. Complete your Android code;
This part is the Android development thing, not my focus and good at, believe is your good at;
2. Generate the C + + code. So;
I assume that you have C + + code that has the functionality you need. ( No you also transplant a fart O (∩_∩) o haha ~)
2.1 C + + code modification
This part of the work, three important points:
1, header file added: #include <jni.h>
2, add extern "C", processing C + + code;
3, the output of the interface function naming must be standardized; Java_ Package _ class _ Method (jnienv *, Jclass,);
Example:
#include <jni.h>
#ifdef __cplusplus
extern "C" {
#endif
Jniexport Jlong Jnicall Java_org_opencv_samples_facedetect_detectionbasedtracker_nativecreateobject
(JNIEnv *, Jclass, jstring, Jint);
#ifdef __cplusplus
}
#endif
Here is only the header file, the specific implementation you can implement in the CPP file;
2.2 Changes to ANDROID.MK files
Add the source file you just added, and add the dependent libraries. (generally need to application.mk, but almost the same, copy the past is good)
Example:
android.mk file ( much like makefile file )
Local_path: = $ (call My-dir)
Include $ (clear_vars)
#OPENCV_LIB_TYPE: =shared
Include: /.. /.. /opencvsdk/native/jni/opencv.mk
Local_src_files: = Detectionbasedtracker_jni.cpp
Local_c_includes + = $ (Local_path)
Local_ldlibs + =-llog-ldl
Local_module: = Detection_based_tracker
Include $ (build_shared_library)
APPLICATION.MK file
App_stl: = gnustl_static
App_cppflags: =-frtti-fexceptions
App_abi: = armeabi-v7a
App_platform: = android-8
2.3 Ndk-build Compilation
Place the above 4 files in the Jni folder and prepare to start compiling the. so file.
As long as you install the version above R7 can not need other plug-ins. Very convenient, configure the environment variables, from cmd into the JNI file or its upper level folder, execute the ndk-build command, start compiling.
For more detailed reference: http://blog.csdn.net/ikerpeng/article/details/42643223
3. Place the. So library in the Android Libs folder;
Copy the following. So file under the Lib file you just compiled, and attach the folder (this is required) to the Libs folder in your Android project;
4. In the Android code, define the interface function to be called and import the library.
Define the interface function, the function name must be the same as the last name in C + +, and then system.loadlibrary ();
You can substitute this function in the Android code.
Example:
public class Peddetectionnative {
static {
System.loadlibrary ("Ped_detection");
}
public static native Boolean ped (byte[] YUV);
}
Next you can use the PED () function in the Android code.
Reprint marked Source: http://blog.csdn.net/ikerpeng/article/details/45393223
Completed above
Iker Cross
April 30, 2015
Android NDk Development Easy Tutorial