当前位置:网站首页>A preliminary study on the use of ndk and JNI
A preliminary study on the use of ndk and JNI
2022-08-08 23:05:00 【Jacky_Lu】
References:
https://blog.csdn.net/qq_25884515/article/details/104250920p>
Create a C++ project
Understanding the CMakeList.txt file,
Set header files and add source files
#Set the header file to the current pathINCLUDE_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.cppv4l2Cocos.cpp )
Also calling Kuba in the library should be
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} )
Define the function parameters and return data in the JAVA file
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");}
Write the implementation of these functions in a C++ file
extern "C" JNIEXPORT jstring JNICALLJava_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);
}
Note that env is an important parameter for linking c++ and java data format conversion
Also study how to directly call the so library without some source code
边栏推荐
猜你喜欢
wps表格分两页断开怎么办?wps表格分两页断开的解决方法
你了解你每天都在用的NAT吗?
The Socket (Socket)
Virtualization type (with picture)
Kubernetes与OpenStack
PHP7.2开发物流自动拣货机流程
MES docks with Simba to realize IMEI number writing and coupling test of Spreadtrum platform
如何使用 Eolink 实现 API 文档自动生成
用工具实现 Mock API 的整个流程
微信小程序错误 undefined Expecting ‘STRING‘,‘NUMBER‘,‘NULL‘,‘TRUE‘,‘FALSE‘,‘{‘,‘[‘, got ]解决方案
随机推荐
机器学习建模高级用法!构建企业级AI建模流水线
JSDay1-合并两个有序数组
JS中的原型与原型链
Analysis of WLAN - Wireless Local Area Network
C语言 库函数汇总2019.10.31
Kubernetes 1.25 中的删除和主要变化
Xcode creates a Dylib plugin deb project
ZCANPRO 通道配置方法
Firewall first contact
Kubernetes 资源核心原理
三国战绩 风云再起 网络版 物品序号 和 基址列表
从洞察到决策,一文解读标签画像体系建设方法论丨DTVision分析洞察篇
套接字(Socket)
iptables防火墙内容全解
wsgw login packet capture record
如何搭建一套自己公司的知识共享平台
关于OD的bp send断点 常用断点(OD)
Dynamic Host Configuration Protocol DHCP (DHCPv4)
Node中的Events模块怎么应用
Virtualization type (with picture)