简体   繁体   English

Android NDK无法加载libc ++ _ shared.so,获取“无法定位符号'rand'引用

[英]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 ,但是一些自定义代码?),但你仍然可以尝试:

  • to use GCC's GNU Standard Library, leaving GCC 4.8 as toolchain 使用GCC的GNU标准库,将GCC 4.8作为工具链

OR 要么

  • to use Clang compiler, leaving libc++ as Standard library 使用Clang编译器,将libc ++作为标准库

AND/OR AND / OR

  • to use static linking for "debugging purposes" (it won't link until something is missing, allowing you to find the cause without messing with Java and JNI) 使用静态链接进行“调试”(在缺少某些内容之前不会链接,允许您在不弄乱Java和JNI的情况下找到原因)

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.

相关问题 是AOSP的libc ++。所以和NDK的libc ++ _ shared.so一样吗? - Is AOSP's libc++.so the same as NDK's libc++_shared.so? OpenCV Android 中的实现 - 未找到“libc++_shared.so” - OpenCV Implementation in Android - "libc++_shared.so" not found 在 OpenCV android 应用程序中启用“libc++_shared.so” - enabling "libc++_shared.so" to be enabled in the OpenCV android application 我在哪里可以下载 Android 的 libc++_shared.so? - Where can I download libc++_shared.so for Android? Android Studio CMake - 共享库缺少 libc++_shared.so? CMake 可以捆绑这个吗? - Android Studio CMake - shared library missing libc++_shared.so? Can CMake bundle this? Clang 链接 .so 库 libc++_shared.so - Clang linking .so library libc++_shared.so Android NDK交叉编译FFmpeg,dlopen失败:找不到符号 - Android NDK Cross Compile FFmpeg, dlopen failed: cannot locate symbol 如何使用 gradle 以编程方式将 libc++_shared.so 包含到我的 APK 中? - How to include libc++_shared.so into my APK programmatically with gradle? Android NDK异常失败:dlopen失败:无法找到“ libtangram.so”引用的符号“ _ZN7Tangram11setPositionEdd” - Android NDK Exception failed: dlopen failed: cannot locate symbol “_ZN7Tangram11setPositionEdd” referenced by “libtangram.so” Android NDK:获取java.lang.UnsatisfiedLinkError:dlopen失败:找不到“libffmpeg.so”引用的符号“signal” - Android NDK : Getting java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol “signal” referenced by “libffmpeg.so”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM