简单了解NDK开发,先生成一个动态库,然后另一个项目调用。
1.生成so包。
1. 创建 ‘MakeSoLib’ Android c++项目
2.在默认cpp内编写自定义so包的方法
#include <jni.h>
#include <string>
extern "C" std::string stringFromLib(){
return "String from Lib!";
}
3. 编译项目 Build-Make Project
如图所示,build文件夹生成了我们需要的so包,包含四种架构。
2.调用so包
1.新建 ‘UseSoLib’ Android c++项目
2.将之前生成的so包拷贝至如下目录
3.修改CMakeLists文件
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
add_library(libtest