设置cmake的最小使用版本,camke_minimum_required(VERSION 3.4.1)
# Sets the minimum version of CMake required to build the native library. cmake_minimum_required(VERSION 3.4.1) # Creates and names a library, sets it as either STATIC # or SHARED, and provides the relative paths to its source code. # You can define multiple libraries, and CMake builds them for you. # Gradle automatically packages shared libraries with your APK. add_library( # Sets the name of the library. native-lib //这是so库的名称 # Sets the library as a shared library. SHARED // 静态库 MODULE就是模块库 # Provides a relative path to your source file(s). src/main/cpp/native-lib.cpp //这里是so库的源文件路径 可以使用通配符) # Searches for a specified prebuilt library and stores the path as a # variable. Because CMake includes system libraries in the search path by # default, you only need to specify the name of the public NDK library # you want to add. CMake verifies that the library exists before # completing its build. find_library( # Sets the name of the path variable. // find_library 这个一般是系统库,放在这个命令里面的不会被打包到我们的apk里面 log-lib //库的特定位置 log库放在log-lib中 # Specifies the name of the NDK library that # you want CMake to locate. log //指定使用的库 ) # Specifies libraries CMake should link to your target library. You # can link multiple libraries, such as libraries you define in this # build script, prebuilt third-party libraries, or system libraries. target_link_libraries( # Specifies the target library. //本地库(自己的库native-lib)想要调用log库的方法,就要在以下命令进行关联 native-lib # Links the target library to the log library # included in the NDK. ${log-lib} //要关联的库,要使用的库)