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框架

 

 

有多个cpp/c文件需要编译的情况处理方式:

1.指定编译路径下所有的文件

#对应需要编译cpp的文件路径
file(GLOB my_srcs "src/main/cpp/*")

add_library( test-lib  SHARED  ${my_srcs})

2.将每个cpp文件变为一个库

add_library( test1-lib  SHARED  native1-lib.cpp)

add_library(test2-lib   SHARED native2-lib.cpp)

 

 

 

 

 

 

posted @ 2020-03-10 18:45  苏小七  阅读(1242)  评论(0编辑  收藏  举报