Question

This is the first time I decided to write here, but I have long time successfully used stackoverflow, thanks to people who spend his time helping others! :)

Now, I have not found information about this, I am trying to use a library which uses Qt in my android application. The problem is that I am not able to load libQt5Core.so. When running Android throw an unsatisfiedLinkError: unknown failure. I have tried to load it in two ways.
First one, with its own Android.mk:

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := Qt5Core
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libQt5Core.so
LOCAL_EXPORT_C_INCLUDES :=  $(LOCAL_PATH)/include \
                            $(LOCAL_PATH)/include/QtCore
include $(PREBUILT_SHARED_LIBRARY)

Second one, adding it manually to lib dir.

I load libraries froma Native.java file in this way:

System.loadLibrary("gnustl_shared");
System.loadLibrary("Qt5Core");
System.loadLibrary("mysharedlibray");
System.loadLibrary("thewholelibrary");

I mysharedlibrary with a Makefile, it's the library which uses Qt. The whole library includes the jni code and mysharedlibrary, I make it using ndk-build.

I have got libQt5Core.so from the Necessitas package, I suppose I can use it out from the Necessitas system.

I also would like make a "standalone shared library" mysharedlibrary with the Qt "inside" it (since I use no Qt at jni in Android" but it does not let me do that.

Thanks a lot!

Was it helpful?

Solution 2

I've found one solution:

static {
    try {
        System.loadLibrary("gnustl_shared");
        System.loadLibrary("Qt5Core");
    } 
    catch( UnsatisfiedLinkError e ) {
        System.err.println("Native code library failed to load.\n" + e);
    }
    System.loadLibrary("mysharedlibray");
    System.loadLibrary("thewholelibrary");
}

If your library uses Qt but just inside itself that works.

OTHER TIPS

To load libQt5Core.so in your android project, you should add dependency to QtAndroid-bundled.jar. You can find the file in the Qt installation directory under the jar directory. After this step you can call System.loadLibrary("Qt5Core"); without UnsatisfiedLinkError.

The reason: QtCore's JNI_OnLoad loads an activity called QtNative when it starts and returns JNI_ERR if it is not found. QtNative is defined in QtAndroid-bundled.jar. I fount anwer here: https://stackoverflow.com/a/25856689/1091536

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top