当前位置:网站首页>ndk和JNI的使用初探
ndk和JNI的使用初探
2022-08-08 23:04:00 【Jacky_Lu】
参考资料:
https://blog.csdn.net/qq_25884515/article/details/104250920
创建C++项目

理解 CMakeList.txt文件,
设置头文件 和 添加源文件
#设置头文件为当前路径
INCLUDE_DIRECTORIES("./")
# 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
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp
v4l2Cocos.cpp )还有 在库里面 调用库巴 应该是
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 )
# 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
# Links the target library to the log library
# included in the NDK.
${log-lib} )
在 JAVA 文件中 定义 调用的 函数 参数 和返回数据
public native String stringFromJNI();
public native int getFrameFromJNI(int[] data);
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("native-lib");
}
在C++文件中 写入这些函数的实现
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_seziocr_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
char pbuf[128];
pCap=new CapCocos();
int d=pCap->OpenVideo("/dev/video0");
sprintf(pbuf,"video0:%d",d);
LOGD("Hello World %d",d);
//return env->NewStringUTF(hello.c_str());
return env->NewStringUTF(pbuf);}
注意 env 是链接 c++ 和 java 的数据格式转换的 重要参数
还要研究怎么 直接调用 so 的库 不需要些 源码
边栏推荐
猜你喜欢

JS中的预编译(AO、GO详解)

Dynamic Host Configuration Protocol DHCP (DHCPv4)

二叉树 层次遍历 及例题

Xcode 创建一个Dylib 插件deb项目

Application Layer Protocol - RADIUS

【YOLOv5】6.0环境搭建(不定时更新)

wps表格怎么调整表格大小?wps表格调整表格大小的方法

用工具实现 Mock API 的整个流程

论文阅读 (66):Explainable Deep Feature Embedding Using Multiple Instance Learning for Pathological Image

laravel6框架跨域请求利器之 Laravel CORS 扩展包的安装和使用
随机推荐
JS中的预编译(AO、GO详解)
Kubernetes资源编排系列之四: CRD+Operator篇
Alipay To Financial Ranking Name Modification
动态主机配置协议DHCP(DHCPv4)
wsgw login packet capture record
iptables firewall content full solution
GIL和池的概念
Kubernetes 企业如何落地
冒泡排序
JSDay2-多个数组的交集
Application Layer Protocol - RADIUS
微信公众号 接口测试平台 获取自定义菜单教程
【Verilog基础】关于芯片中信号串扰的理解
套接字(Socket)
ArcPy set the unique identification code
JSDay1-合并两个有序数组
【PP-YOLOv2】测试自定义的数据集
thinkphp5 if else的表达式怎么写?
CTFSHOW_WEB入门web213
免费ARP