问题标签 [jniwrapper]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 如何使用JNI从C调用JAVA方法
我想使用 JNI (Java Native Interface) 来调用特定的 java setter 方法,将一个 short[] 缓冲区作为参数传递给它。
Java 方法实现如下所示:
从我的 C 函数内部,如何使用 JNI 调用此方法。
我的代码目前如下所示:
当我运行它时,它setLeftDataID
是 allays NULL
。
请注意,jobj
参数是我传入的包含setPcmLeft
实现的对象。
java - 无法在独立的 java 应用程序上运行 PJSIP-JNI Wrapper
我需要一些将 PJSIP 用作独立 Java 应用程序的文档,以了解流程并实现 Java Wrapper。我已经下载了 PJSIP-JNI 包装器,但我无法理解如何运行该应用程序。我真的很震惊很多天。请有人帮助我将 PJSIP-JNI 用作独立的 Java 应用程序,例如,我想通过我的主类测试与我的 SIP 服务器的连接。如果有人可以建议其他一些库,那么它真的很棒。
java - 无法将 .so 库从工作项目集成到另一个项目
我有一个工作项目,我用来JNI
从C
库中调用方法。
我的项目结构:
以及加载库的代码:
它运作良好。但是直到我尝试将此功能集成到其他项目中。我复制jni
和libs
文件夹。也都three classes
没有RemoveBackgroundActivity
(测试活动)。当我编译这个项目时,我有一个例外:
你知道如何解决这个问题或其他方法吗?
java - Issue with writing FaceRecognizer for Java with OpenCV 2.4.8
I have been given a project based around face recognition written in JavaCV to be improved. The idea was to either rewrite the program using C++ or write JNI bindings to still use Java. I did some research and according to the official website OpenCV as of version 2.4.4 has bindings for Java and Python. And so, since the official website stated so I decided to go with it. Please note I haven't programmed in C++ before nor have I written any JNI wrappers in the past. If the official website didn't state that it includes bindings for Java I would just write it with C++ using Qt Digia.
This way or another I did everything else that I wanted to do with the Java project and was left with the face recognition part. Unfortunately according (Relevant question #1, Relevant question #2) I found out that there is a bug with FaceRecognizer and that JNI wrapper for face recognition has to be written by hand.
I found a pretty good jni c++ java tutorial and I tried to use that with the code mentioned in Relevant question #1 linked above. The screenshot below shows what I have got right now.
The code is as follows:
LBPHFaceRecognizer.java
LBPHFaceRecognizer.c
makefile
All in all I managed to create facerec.dll, but there are a number of problems. First when I was creating the facerec.dll the LBPHFacerecognizer.java did not have the import at the top, because it was complaining about it. I added it afterwards just not to see the error.
Secondly the .c code complains about everything as seen on the screenshot below.
and interestingly enough it doesn't complain about the jni.h import whereas the header file as seen on screenshot below does.
That's it, can someone have a look at it and tell me if I've done it correctly? Is there something I should change? Are those errors ok considering the fact the the dll has been created? Or maybe someone has done it in the past and is willing to share the dll file. I haven't gotten around to testing it with the java equivalent of JavaCV code yet.
I use OpenCV 2.4.8, Win 7 64bit, Mingw 64 bit, Java 64 bit 7_0_51 release, Eclipse 64 bit.
Thanks in advance.
android - 单元测试 JNI 调用
我有一些 C++ 代码的 Android JNI 包装器。C++ 代码有它自己的一组单元测试。
我想为 JNI 包装类编写 Java 单元测试。
有没有办法.so
从桌面控制台(例如在 Windows 上)对 Android JNI 包装器 API 进行单元测试?也许使用桌面 Java 框架但使用所有 Android SDK 调用?
java - 如何从 Java 进行同步\异步本机调用
我正在为 Android 开发一个国际象棋游戏,并计划使用用 C++ 编写的 AI 引擎。所以,我必须进行从 Java 到 C++ 的本地方法调用。来源如下所示:
计算机.java
和 c++ 文件:mylib.cpp
当我从主活动中调用 Computer.makeMove() 时,程序崩溃,logcat 窗口中没有任何错误信息。我不知道这个问题,但似乎是因为 generateMove() 执行。
当级别设置为 10 时,generateMove() 调用需要很长时间(最多 15 秒)才能完成。我认为 Android 活动不能等到它完成并崩溃。
如果 level 设置为 1,则一切正常,这意味着 generateMove() 可以完成并立即返回执行结果。
我想我需要以同步方式拨打电话,但我不知道。有没有办法以同步/异步方式进行本机调用?
java - jni getMethodID 用于获取构造函数 ID 时返回 Null
classNameC 是一个全局变量,它的类没有构造函数。然后在其他函数中,我这样使用它:
这个构造函数有 2 个参数,一个是长的,下一个是布尔值。这个类有 2 个构造函数,另外一个没有参数并且用 0 初始化成员。
当我运行它时,它成功打印到创建的 SWIGTYPE p void 类并且 SWIGTYPE p void 构造函数为 NULL ,然后它给出了这个错误:
Java 运行时环境检测到一个致命错误:
SIGSEGV (0xb) 在 pc=0x00007f7ec503fa7b,pid=25307,tid=140182441326336
JRE 版本:Java(TM) SE Runtime Environment (7.0_65-b17) (build 1.7.0_65-b17) Java VM: Java HotSpot(TM) 64-Bit Server VM (24.65-b04 mixed mode linux-amd64 compressed oops) 有问题框架:V [libjvm.so+0x657a7b] JNI_ArgumentPusherVaArg::JNI_ArgumentPusherVaArg(_jmethodID*, __va_list_tag*)+0x1b
核心转储写入。默认位置:/home/manish/rathi/libdmc/dmcore/include/core 或 core.25307
包含更多信息的错误报告文件保存为:/home/manish/rathi/libdmc/dmcore/include/hs_err_pid25307.log
如果您想提交错误报告,请访问:
http ://bugreport.sun.com/bugreport/crash.jsp中止(核心转储)
registry - 通过 JNIWrapper 在 Windows 7 64 位上写入注册表 - 性能问题
我们的安装使用jniwrapper
库。现在,我们开始在 Windows 7 64 位机器上安装,但遇到了问题。
要将值写入注册表,我们使用函数
com.jniwrapper.win32.registry.RegistryKeyValues.put()
只要我们在系统管理员用户的上下文中安装,当然还有提升,安装就可以正常工作。但是,当我们以另一个管理用户身份登录,提升他的权限并开始安装时,则需要更多时间。更进一步的分析表明,现在上述jniwrapper
函数每次注册表写入操作都需要大约 15 秒的时间!
你知道如何解决 64 位版本的 Windows 7 上的问题吗?
install4j - 在 install4j 安装程序中使用 jniwrapper 自定义代码
我们有一个用 install4j 编写的安装脚本。
我们的安装程序需要从库 jniwrap.dll 中调用自定义代码。我们将 jniwrap.dll 包含到 install4j 项目中,并在“安装程序”>“自定义代码和资源”中声明它。
不幸的是安装失败:jniwrap.dll 无法加载,因为它不在搜索路径中。
你知道如何修复错误吗?jniwrapper 的许可文件呢?我们是否也必须将它插入到 install4j 项目中?
先感谢您。
java - JNI - SetByteArrayRegion 不起作用
我在包装代码中遇到了一些关于编码/解码音频的问题,我调试了我的代码,最后发现SetByteArrayRegion
它不能按预期工作。开始了:
encoded
和jencoded
(ie )中的值encoded_test
不匹配!多次调用该程序后,encodeDbg
文件内容如下:
前 16 个字节有问题,而数组的其余部分都可以。任何建议都受到高度赞赏。
编辑:
我在 linux(使用 mingw)上编译 JNI 部分(C 东西),并将 dll 复制到运行 Java 应用程序的 Windows。这种跨平台操作会导致问题吗?我是否需要向编译器或链接器添加一些额外的标志/参数?
第二次编辑:
我稍微更改了代码以查看调用encoded
后的内容。SetByteArrayRegion
代码和输出如下:
样本输出: