Cannot Load Library: Reloc_Library[1285]: Cannot Locate 'Rand'

Cannot load library: reloc_library[1285]: cannot locate 'rand'

This happens if you've built your native components with the android-21 target, but are trying to run it on a device with an older Android version. Unless you take very special care, you can't run binaries built with the android-21 target on older devices. For basic C functions, it shouldn't matter which target version between android-3 and android-20 you use, it should work on all of them, but if you use android-21 it only works on that version and newer.

See https://stackoverflow.com/a/27093163/3115956 for more details on this issue.

Android NDK cannot load libc++_shared.so, gets cannot locate symbol 'rand' reference

Problem is entirely on native side. Java has no any clue on what's happening past the JNI boundary. 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).

You should resolve all the symbols on the native side, i.e. you should correctly link C++ Standard Library to your libcom.testandroid.LibAndroidBridge.so.

I'd advised against mixing { gcc toolchain (4.8 in your case) + libc++ ("c++_shared") } or { clang + libstdc++ } on Android. 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. 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:

  • to use GCC's GNU Standard Library, leaving GCC 4.8 as toolchain

OR

  • to use Clang compiler, leaving libc++ as Standard library

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)

Android Studio 1.3 NDK : cannot locate 'srand'

You need to build the native sources against a SDK version prior to 21, if you want the code to run on older versions. (The java part can still be built using the latest SDK.)

If it's ok to lower the generic compileSdkVersion, try lowering it to 19 or 20. If not, you might want to try adding compileSdkVersion 19 within the ndk block.

See https://stackoverflow.com/a/27338365/3115956 and https://stackoverflow.com/a/27093163/3115956 for more explanation on the issue.

UnsatisfiedLinkError when compiling with API21

Yes - the android libc headers have changed in API 21. Some functions that didn't exist previously were redirected to other functions in the older headers. Therefore you can't really build with API 21 if you want to run on older devices, unless you take great care to work around such issues. If you need to use newer native APIs from API 21 but still be compatible with older devices, you need to do manual work to achieve this anyway.

If you only want the newer API for the java side, just set a separate APP_PLATFORM=19 in Application.mk, while building the java side with a newer SDK.

See Cannot load library: reloc_library[1285]: cannot locate 'rand' for more details on this issue.

Android NDK returns an error undefined reference to 'rand'

Contrary to the initial impression (from the subject), this isn't (directly) a duplicate of Cannot load library: reloc_library[1285]: cannot locate 'rand'.

It seems that when configuring libvpx with --target=x86-android-gcc, it actually doesn't automatically pick an android compiler or try to use android headers (contrary to what it does for armv7-android-gcc). (In fact, if you compile with --target=x86-android-gcc on OS X, it doesn't even build linux/android binaries, it will end up building a binary for OS X.)

Instead it builds pretty much as usual, using the normal system compiler, with the normal system headers (unless you manually specify them), which contain a normal rand function, which isn't available on Android. (On Android versions prior to 5.0, the rand function in stdlib.h is an inline function that actually maps to the lrand48 function, which is what the binary ends up linking to).

(Also, when building for android on arm, it doesn't seem to allow you to pick which android version you're targeting, so if your NDK contains android-21, it seems that it will try to build with that, which can also give you similar errors, such as in Cannot load library: reloc_library[1285]: cannot locate 'rand'.)

Since the configure script magic doesn't seem to set up the right things for building for x86 android (as it does for arm), you should be able to set it up yourself instead, which requires setting a bit more parameters:

export PATH=<NDK>/toolchains/x86-4.8/prebuilt/*x86*/bin:$PATH
ASFLAGS="-D__ANDROID__" CROSS=i686-linux-android- LDFLAGS="--sysroot=<NDK>/platforms/android-9/arch-x86" ./configure --target=x86-android-gcc --extra-cflags="--sysroot=<NDK>/platforms/android-9/arch-x86" --disable-examples
make

With this, I'm able to build a libvpx.a which should be built against the right headers, which hopefully should work fine for you.

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol srand referenced by xx.so

As Dan pointed it out in comments, your problem certainly comes from compiling against an android api level >=21.

To solve your issue, you can compile your code against the same platform than your APK's minSdkVersion.

How are you using the NDK? If you're using ndk-build, add an Application.mk file next to your Android.mk file, with for content APP_PLATFORM:=android-14 (where 14 is your minSdkVersion).

Runtime linking error with NDK using STL

This seems to be the same issue as a lot of other recent ones, like Cannot load library: reloc_library[1285]: cannot locate 'rand'. The issue is that you are building your app using the android-21 API. The signal function (just like rand) used to be an inline function in a header (redirecting the code to bsd_signal and lrand48 respectively), but in android-21 new functions were added, so these are no longer inlines in the header.

Therefore, if you want your app to run on platforms earlier than android-21, you need to make sure you build the native code using the lowest API level you want your code to run on, e.g. by adding APP_PLATFORM := android-9 in jni/Application.mk.

If you need features from newer ones, android-19 should also work mostly pretty well. For verions prior to 21, newer platform versions only added new functions that didn't exist before (but the old functions behaved like before), so if you only are using functions that existed in android-N, it should work on android-N even if you built it with android-19 (for N < 19). But 21 changed all of this, functions that existed before (but redirected to other functions) now link to a different name (the more correct one to be honest), which wasn't available before.

This doesn't affect what API level you can build your java code (if any) with, though - you can still build that part targeting the latest API if you want to.



Related Topics



Leave a reply



Submit