Android Studio2.2 directly after the creation engineer to add the NDK support, added, the main folder will be more than a native-lib.cpp this file, if only for a simple NDK interface, it seems that this is the end. You can program directly under the Native-lib.cpp.
However, if you use a third-party library, you have to reconfigure it. So far, most of the articles on the Internet are. Mk Configuration method, according to their steps, in as a step by step to do it seems difficult to succeed.
Android Studio2.2 using CMake as a cross-platform compilation tool, after creating a project, the JNI configuration is managed by CMake, in the Cmakelist file under the Priject folder.
CMake a set of his own writing rules, according to the introduction of different, first write two demo
1,native-lib file calls third-party libraries
The third party libraries is compiled into so library directly call, configure so library, the corresponding header file also add
#譬如加载一个FFMPEG模块
1 include_directories (${pathtoffmpeg}/include) #添加ffmpeg对应的头文件目录,${pathtoffmpeg} is a previously configured path and can be replaced with Include_ Directories (e:/ffmpeg/include) This path format
Add_library (ffmpeg SHARED imported) #添加库文件, in fact, is the introduction of so files, import represents the meaning of the introduction from a third party
3 Set_target_properties (FFmpeg properties Imported_location ${pathtoproject}/app/src/main/jnilibs/${android_abi}/
4 target_link_libraries ($\{log-lib} native-lib ffmpeg) #为native-lib load ffmpeg library.
This allows the FFmpeg module to be called in Native-lib.
2. cpp files written by yourself
#加载coreAlg核心代码add_library (corealg SHARED src/main/cpp/coreAlg.cpp) #添加库文件, this actually has as to be compiled into so files target_link_libraries (native-lib ${log-lib} corealg) call-lib #native Corealg
Cmakelist NDK configuration in Android Studio