iOS上的本机JNI [英] Native JNI on iOS
问题描述
我已经能够成功构建一个C ++共享库,并使用Java本地函数在Android上访问该代码。我试图在iOS上重现这种努力。使用CMake,我能够配置和构建我的共享库为.dylib,并在我的iPhone / iPad模拟器上加载它 System.loadLibrary()
。但是,当我调用本机函数时,我得到一个 UnsatisfiedLinkError
。使用 nm
的快速检查验证我已按预期导出JNI函数。有人能告诉我我做错了什么?
I have been able to successfully build a C++ shared library and use Java native functions to access that code on Android. I am trying to reproduce this effort on iOS. Using CMake, I was able to configure and build my shared library as a .dylib, and load it with System.loadLibrary()
on my iPhone/iPad emulator. However, when I call a native function I get an UnsatisfiedLinkError
. A quick check with nm
verifies that I have exported the JNI functions as I expected. Can somebody tell me what I'm doing wrong? Do I need to modify the native function names for Apple somehow?
nm
:
000000000011Ce0 T _Java_com_test_Native_getPointer
Native.java
:
public static native long getPointer();
在C ++代码中:
extern "C" {
JNIEXPORT jlong JNICALL Java_com_test_Native_getPointer(JNIEnv* env, jobject thiz)
{
return (jlong)0;
}
错误是:
java.lang.UnsatisfiedLinkError: com/test/Native.getPointer(I)J
已解决!
我手动输入方法签名,看到另一个屏幕,关键元素:
I had typed the method signature by hand looking at another screen, and accidentally left out a crucial element:
JNIEXPORT jlong JNICALL Java_com_test_Native_getPointer(JNIEnv* env, jobject thiz, int test)
删除 int test
解决了问题。
推荐答案
解决方法:
我手动键入方法签名,另一个屏幕,并意外地遗漏了一个关键的元素:
SOLVED: I had typed the method signature by hand looking at another screen, and accidentally left out a crucial element:
JNIEXPORT jlong JNICALL Java_com_test_Native_getPointer(JNIEnv* env, jobject thiz, int test)
删除 int test
解决了问题。
这篇关于iOS上的本机JNI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!