Search code examples
javaandroidc++android-ndkandroid-5.0-lollipop

UnsatisfiedLinkError when compiling with API21


My project uses NDK r10d for the c++ code. When I compile the project with API19 it works great, but when I compile it with API21 it crashes on runtime.

When the c lib is loaded I get:

dlopen("/data/app-lib/com.my.app-2/libMyCode.so") failed: dlopen failed: cannot locate symbol "stpcpy" referenced by "libMyCode.so"...

Then it crashes on:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "stpcpy" referenced by "libMyCode.so"...

I use OnePlus One running Android4.4.4 to test it on both cases.

Any ideas?


Solution

  • 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.