CMake 构建脚本是一个纯文本文件,您必须将其命名为 CMakeLists.txt,并在其中包含 CMake 构建您的 C/C++ 库时需要使用的命令。如果您的原生源代码文件还没有 CMake 构建脚本,您需要自行创建一个,并在其中包含适当的 CMake 命令。
可以用你写的cpp源文件生成一个so
add_library( # Specifies the name of the library. native-lib # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). src/main/cpp/native-lib.cpp )也可以直接导入已有的库(import)
add_library( imported-lib SHARED IMPORTED ) set_target_properties( # Specifies the target library. imported-lib # Specifies the parameter you want to define. PROPERTIES IMPORTED_LOCATION # Provides the path to the library you want to import. imported-lib/src/${ANDROID_ABI}/libimported-lib.so )使用 include_directories() 命令并包含相应头文件的路径,使CMake 能够在编译时定位你的头文件:
include_directories( imported-lib/include/ )设置接口库对第三方库的链接,其中第一个参数为接口库,后面参数为第三方库
target_link_libraries(libimported-lib)
未完待续........