Cmakelist NDK configuration in Android Studio

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.