当前位置:网站首页>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 的库 不需要些 源码
边栏推荐
猜你喜欢
随机推荐
Taro小程序跨端开发入门实战
SVN Update和Commit执行文件
Unity Text值递增或递减效果
Go语言并发编程基础上下文概念是什么
wps a3格式怎么转换成a4?wps a3格式转换成a4的方法
套接字(Socket)
The second side of Tencent technical support internship - Tencent's father's luck is so sudden (offer received)
Unity 创建重复使用的子节点,避免生成多个子节点
【Bug解决】ValueError: Object arrays cannot be loaded when allow_pickle=False
C2758105-Flash 驱动配置参考
我曾七次鄙视自己的灵魂——纪伯伦
【Verilog基础】PPA优化问题总结(含面积优化、速度优化)
【Pytorch】学习笔记(一)
用工具实现 Mock API 的整个流程
CTFSHOW_WEB入门web213
动手写prometheus的exporter-01-Gauge(仪表盘)
SublimeText 3清凉编辑器php开发自定义颜色文字主题配置加汉化
支付宝 To 理财排行名称修改
Node中的Events模块怎么应用
深拷贝与浅拷贝