Viktor Sehr
Viktor Sehr

Reputation: 13099

Unable to load libnative-activity.so when CMAKE_BUILD_TYPE is set to anything but debug

After updating NDK to version 19 my application throws a UnsatisfiedLinkError with this message "Unable to load native library "/data/app/com.company.appname-SkXFrxADQ610MNjJr7Ak3A==/lib/arm64/libnative-activity.so": null" at start, and then terminates.

Anyone knows what is causing this error, and how to resolve it?

Notes:

1) When CMAKE_BUILD_TYPE is set to Debug, everything works fine, regardless of optimization (-O) level or DEBUG_MODE setting.

2) This did not happen prior to NDK 19

3) I do call app_dummy(), even though the call is deprecated and not necessary

4) The application uses android_native_app_glue.h/.c i.e no Java at all.

5) The exception libname is "native-activity", and funcname is "ANativeActivity_onCreate"

Update:

From the NDK r19 revision history Google says ndk-depends has been removed. We believe that ReLinker is a better solution to native library loading issues on old Android versions. I suppose this is relevant, guessing ndk-depends preserved the native activity, but as a native glue application does not contain any java code, how can I apply ReLinker from code?

Upvotes: 0

Views: 752

Answers (1)

Dan Albert
Dan Albert

Reputation: 10509

fread_unlocked isn't available until Android P. You can't use that function in an app with a minSdkVersion lower than 28.

This shouldn't have compiled unless you've given CMake an incorrect ANDROID_PLATFORM, as the symbol wouldn't have been available to link against. If you're building your app with gradle and externalNativeBuild then gradle configures this for you based on your minSdkVersion. If you're not, you should probably switch to using it as it provides these safeguards.

Upvotes: 1

Related Questions