android studio CMake NDK:配置笔记

工具下载:在SDK-Tool中下载CMake, LLDB ,NDK。

项目创建

 

 配置最后页面的这两项也选上,方便代码调试。

配置库名称及库的输出路径和格式:

1.配置CMakeLists.txt

#设置编译时CMake的最低需求版本
cmake_minimum_required(VERSION 3.4.1)

#设置生成的so动态库最后输出的路径
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../jniLibs/${ANDROID_ABI})
add_library(
#添加的库名
      test-lib
        #库的类型:SHARED表示动态so库,STATIC表示静态a库
      SHARED
#编译的cpp文件源文件路径
      src/main/cpp/native-lib.cpp)

#设置NDK本地库里你想使用的库的引用名
find_library( # Sets the name of the path variable.
log-lib

# Specifies the name of the NDK library that
# you want CMake to locate.
log)

#设置目标so库生成时,要关联的库
target_link_libraries( # Specifies the target library.
test-lib

# Links the target library to the log library
# included in the NDK.
${log-lib})

2.配置gradle文件,指定so库CPU框架

 

猜你喜欢

转载自www.cnblogs.com/suxiaoqi/p/12457818.html