关于android studio调用第三方so库的细节问题,如何建立Java和so库之间的通信?

关于android studio调用第三方so库的细节问题,如何建立Java和so库之间的通信?

问题描述:

最近开始研究ndk,因为c++不懂,所以比较吃力。
目前了解了c++文件的调用
1.ndk环境配置
2.c++文件导入
3.CmakeLists.txt文件配置
4.通过native-lib 建立Java和c++通信,函数调用
关于第三方so库调用网上的教程看了很多,但是因为非常小白,很多细节还是不明白,
关于so库的导入已经了解了,但是Cmakelists.txt文件里面该如何编写,
以及Java和so库如何通信,调用函数还是搞不懂。
比如说我有a.so, b.so, c.so三个文件,他们之间相互关联,
有一个void test(int a, int b)可调用的函数,那么在Java和CmakeLists.txt中我该如何操作呢?
希望大神可以指点一下,非常感谢!

windows的库函数需要使用特殊的方式导出,如下所示:
#ifndef VFP_DLL_API
#if (defined _MSC_VER) && (defined USE_DLL)
// 为什么不适用 stdcall, 因为测试发现 JNA 好像不支持, 待确认
#define VFP_DLL_CALLCONV _cdecl
#if defined DLL_EXPORT
#define VFP_DLL_API __declspec(dllexport)
#else
#define VFP_DLL_API __declspec(dllimport)
#endif
#else
#define VFP_DLL_CALLCONV
#define VFP_DLL_API
#endif
#endif
然后这样声明函数
VFP_DLL_API void VFP_DLL_CALLCONV test(int a, int b){}
CMakeLists不需要特殊处理,Java端的话,

public class HelloWorld {
public native void test(int a, int b);//所有native关键词修饰的都是对本地的声明
static {
System.loadLibrary("mylib");//载入本地库
}
public static void main(String[] args) {
test(1,2);
}
}

可以参考:
https://baike.baidu.com/item/JNI/9412164?fr=aladdin