iOS上的UnsatisfiedLinkError但不是Android,loadLibrary总是成功 [英] UnsatisfiedLinkError on iOS but not Android, loadLibrary always succeeds
问题描述
我有一些Java和C ++代码,我可以在这两个平台上编译并构建本机库。我可以验证库包含我期望的功能,Java能够在Android和iOS上加载库。在Android上一切顺利,没有崩溃,但在iOS上我得到一个非常令人失望的错误:
I have some Java and C++ code that I can compile on both platforms and build native libraries. I can verify that the libraries contain the functions I expect, and Java is able to load the libraries on Android and iOS. On Android everything goes smoothly with no crash, but on iOS I get a very frustrating error:
2015-05-11 11:34:48.418 IOSLauncher[52454:851038] [info] test: initializing native libraries...
2015-05-11 11:34:48.418 IOSLauncher[52454:851038] [info] test: library path set to: "/Users/test/Library/Developer/CoreSimulator/Devices/A189459D-B2D5-4E78-A6E4-A7EAD19DA017/data/Containers/Bundle/Application/DF265D55-DA3C-4C10-851D-20591C4C8C06/IOSLauncher.app"
2015-05-11 11:34:48.419 IOSLauncher[52454:851038] [info] test: loading native libraries on x86_64...
2015-05-11 11:34:48.419 IOSLauncher[52454:851038] [info] test: test
2015-05-11 11:34:48.424 IOSLauncher[52454:851038] [info] test: loaded libraries successfully
java.lang.UnsatisfiedLinkError: com/test/Native.getPointer()J
at com.test.Native.getPointer(Native Method)
at com.test.WavApp.initNativeEngine(WavApp.java)
at com.test.WavApp.create(WavApp.java)
at com.badlogic.gdx.backends.iosrobovm.IOSGraphics.draw(IOSGraphics.java)
at com.badlogic.gdx.backends.iosrobovm.IOSGraphics$1.draw(IOSGraphics.java)
at com.badlogic.gdx.backends.iosrobovm.IOSGraphics$1.$cb$drawRect$(IOSGraphics.java)
at org.robovm.apple.uikit.UIApplication.main(Native Method)
at org.robovm.apple.uikit.UIApplication.main(UIApplication.java)
at com.test.IOSLauncher.main(IOSLauncher.java)
BUILD SUCCESSFUL
Total time: 18.262 secs
java代码在com / test / Native.java中:
A snapshot of the java code in com/test/Native.java:
static
{
System.loadLibrary("test");
Log.i("loaded libraries successfully");
}
public static native long getPointer();
public static native void freePointer(long enginePointer);
以及编译为 libtest.dylib
:
extern "C"
{
JNIEXPORT jlong JNICALL Java_com_test_Native_getPointer(JNIEnv* env, jobject thiz)
{
return (jlong)(new PointerTest());
}
JNIEXPORT void JNICALL Java_com_test_Native_freePointer(JNIEnv* env, jobject thiz,
jlong enginePtr)
{
if ((PointerTest*)enginePtr)
delete (PointerTest*)enginePtr;
}
}
有关构建共享库的更多信息:
Some more info about the built shared library:
Release$ file libtest.dylib
libtest.dylib: Mach-O 64-bit dynamically linked shared library x86_64
并验证导出:
Any ideas? This has been driving me crazy for hours. I can reproduce this error on my Android device by simply using a different library and searching for that function. I'm guessing xcode is somehow hiding or stripping the symbols, but that doesn't seem to correlate with my nm
output above which shows they are there.
任何想法?这一直驱使我疯了数小时。我可以通过简单地使用不同的库并搜索该功能,在我的Android设备上重现此错误。我猜xcode是以某种方式隐藏或剥离的符号,但这似乎与我的 nm
输出上面显示他们在那里。
推荐答案
是在我面前,像往常一样,在这一行:
libtest.dylib: Mach-O 64-bit dynamically linked shared library x86_64
为iOS构建,架构应该是armv7 +。配置错误的xcode子项目。
Building for iOS, the architecture should be armv7+. Misconfigured xcode subproject.
这篇关于iOS上的UnsatisfiedLinkError但不是Android,loadLibrary总是成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!