Search code examples
androidandroid-ndkcrashjava-native-interfaceandroid-ndk-r7

Android NDK built library crahes on devices but runs fine in emulator


I want to make DSP calculations by native code. This works well within the emulator (Android 4.2.2). But on several devices (Android 7 and 9) the lib built by the NDK let the app crash directly on executing System.loadLibrary. But: a downloaded lib loads without problems when I put it into my APK.

I confess, for the main app I am using an old Eclipse IDE on Windows, targeting for API 26. My NDK is a small r7, running on Ubuntu. But my lib only makes calculations on byte arrays in standard c, no Android things are accessed here.

The native code compiles free of warnings and errors and is built for armeabi and armeabi-v7a. In the APK the libxyz.so files are in the correct folders. The names of the export functions should be correct. But even if there are no declarations for them in the Java class and nothing native is called, the crash directly occurs on static { System.loadLibrary("libxyz.so"); }

Can my lib binaries be incompatible?

Thanks for any help!

Update: The libs indeed were incompatible, see comments below.


Solution

  • Finally I could read the logcat from a device (by command line adb, in Eclipse this was not working). The problem seems to be caused by "text relocations" in the binaries.

    Logcat: "java.lang.UnsatisfiedLinkError ... dlopen failed ... libxyz.so has text relocations"

    Updating to a newer NDK (9) fixed the TEXTREL bug. Now System.loadLibrary and calling the native methods works on newer APIs. So I had to install 1,4 GB of NDK for calculating things in standard c.