解决UnsatisfiedLinkError: dlopen failed: cannot locate symbol "stpcpy" referenced by ".so"

解决 UnsatisfiedLinkError: dlopen failed: cannot locate symbol "stpcpy" referenced by "xxx.so" 的问题

网上搜到的原因是说这个问题是由于ndk 的 compile api 版本 21 遗弃了 stpcpy 以及其他一些接口,所以导致有些旧系统上面运行时会崩溃

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 studio 用的gradle 是 experimental 版本的话要设置 APP_PLATFORM 则需要如下设置:

android.ndk {
    toolchainVersion "4.9"    // DK_TOOLCHAIN_VERSION
 
    // APP_PLATFORM
    // Note this must be >=21 for 64 bit architectures
    platformVersion 21
 
    stl "c++_static"      // APP_STL
 
    // APP_ABI
    abiFilters.addAll(["armeabi-v7a", "arm64-v8a", "x86", "x86_64"
    ])
}

Building Native Android Libraries with the Latest Experimental Android Plugin

你可能感兴趣的:(解决UnsatisfiedLinkError: dlopen failed: cannot locate symbol "stpcpy" referenced by ".so")