[英]Android NDK cannot load libc++_shared.so, gets "cannot locate symbol 'rand' reference
In my java class I have this: 在我的java类中,我有这个:
static
{
System.loadLibrary("c++_shared");
System.loadLibrary("com.testandroid.LibAndroidBridge");
}
And my Application.mk has this: 我的Application.mk有这个:
NDK_TOOLCHAIN_VERSION:=4.8
APP_STL := c++_shared
APP_ABI := x86
Things build fine, but when I run the app (on emulator or device, so x85 and arm) I get this in LogCat: 事情很好,但是当我运行应用程序时(在模拟器或设备上,所以x85和arm)我在LogCat中得到了这个:
02-13 12:00:32.174: D/dalvikvm(2142): Trying to load lib /data/app-lib/com.testandroid-1/libc++_shared.so 0xb0fcfc60
02-13 12:00:32.174: D/dalvikvm(2142): Added shared lib /data/app-lib/com.testandroid-1/libc++_shared.so 0xb0fcfc60
02-13 12:00:32.174: D/dalvikvm(2142): No JNI_OnLoad found in /data/app-lib/com.testandroid-1/libc++_shared.so 0xb0fcfc60, skipping init
02-13 12:00:32.174: D/dalvikvm(2142): Trying to load lib /data/app-lib/com.testandroid-1/libcom.testandroid.LibAndroidBridge.so 0xb0fcfc60
02-13 12:00:32.174: E/dalvikvm(2142): dlopen("/data/app-lib/com.testandroid-1/libcom.testandroid.LibAndroidBridge.so") failed: dlopen failed: cannot locate symbol "rand" referenced by "libcom.testandroid.LibAndroidBridge.so"...
02-13 12:00:32.174: W/dalvikvm(2142): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/testandroid/AriesLib;
02-13 12:00:32.174: D/AndroidRuntime(2142): Shutting down VM
02-13 12:00:32.174: W/dalvikvm(2142): threadid=1: thread exiting with uncaught exception (group=0xb0cb0b20)
02-13 12:00:32.174: E/AndroidRuntime(2142): FATAL EXCEPTION: main
02-13 12:00:32.174: E/AndroidRuntime(2142): Process: com.testandroid, PID: 2142
02-13 12:00:32.174: E/AndroidRuntime(2142): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "rand" referenced by "libcom.testandroid.LibAndroidBridge.so"...
02-13 12:00:32.174: E/AndroidRuntime(2142): at java.lang.Runtime.loadLibrary(Runtime.java:364)
Would anyone know why this is failing to import the c++_shared.so library? 有谁知道为什么这不能导入c ++ _ shared.so库?
The real error is something else: rand() is not present, because of Android-21 incompatibilities. 真正的错误是别的:rand()不存在,因为Android-21不兼容。
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "rand" referenced by
See this thread for more info. 有关详细信息,请参阅此主题 。
The recommended fix is to downgrade your API in jni/Application.mk and set it to something lower than Android-21 . 建议的解决方法是在jni / Application.mk中降级您的API并将其设置为低于Android-21的值 。 If you need Android-21 then Google actually recommends shipping multiple APK files.
如果您需要Android-21,那么Google实际上建议您发送多个APK文件。 Ugh.
啊。
Problem is entirely on native side. 问题完全在原生方面。 Java has no any clue on what's happening past the JNI boundary.
Java对JNI边界之外发生的事情没有任何线索。 You cannot make two native libraries go along this way.
您无法通过这种方式创建两个本机库。 Especially, C++ standard library (it has no any symbols easily and reliably accessible by JNI).
特别是,C ++标准库(JNI没有任何容易且可靠地访问的符号)。
You should resolve all the symbols on the native side, ie you should correctly link C++ Standard Library to your libcom.testandroid.LibAndroidBridge.so
. 您应该解决本机端的所有符号,即您应该正确地将C ++标准库链接到
libcom.testandroid.LibAndroidBridge.so
。
I'd advised against mixing { gcc toolchain (4.8 in your case) + libc++ ("c++_shared") } or { clang + libstdc++ } on Android. 我建议不要在Android上混用{gcc toolchain(在你的情况下为4.8)+ libc ++(“c ++ _ shared”)}或{clang + libstdc ++}。 It should work theoretically on desktop Linux or OSX, but there are still portability issues and some quirks persist on Android, depending on NDK version, target, and some "random" factors.
它理论上应该适用于桌面Linux或OSX,但仍存在可移植性问题,并且Android上存在一些怪癖,具体取决于NDK版本,目标和一些“随机”因素。 So it doesn't always work.
所以它并不总是有效。
Unfortunately you did not provide the code where you are using rand
(maybe it's even non Standard Library rand
, but some custom code?), but you can still try: 不幸的是你没有提供你使用
rand
的代码(也许它甚至是非标准rand
,但是一些自定义代码?),但你仍然可以尝试:
OR 要么
AND/OR AND / OR
You don't have to write 你不必写
System.loadLibrary("c++_shared");
just include :- 只包括: -
APP_STL := c++_shared
in your Application.mk That should make it work and now libc++_shared.so will be bundled 在你的Application.mk中应该使它工作,现在libc ++ _ shared.so将被捆绑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.