I am trying to include a shared library with my android app. I have built the library with the NDK and have added it both by using Add Library in the UI and under deployment configurations added the library as an additional library.
My pro file looks like:
# Add more folders to ship with the application, here
folder_01.source = qml/AndroidUI
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
# Installation path
# target.path =
# Please do not modify the following two lines. Required for deployment.
ANDROID_EXTRA_LIBS = ../../android-ext/lib/libopus.so
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../android-ext/lib/release/ -lopus
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../android-ext/lib/debug/ -lopus
else:unix: LIBS += -L$$PWD/../../android-ext/lib/ -lopus
INCLUDEPATH += $$PWD/../../android-ext/include/opus
DEPENDPATH += $$PWD/../../android-ext/include/opus
The program itself is just the hello world program which I am using to see how I add a shared library. So very few changes and it looks like this:
int main(int argc, char *argv)
Application app(argc, argv);
qDebug() << "Hello world!";
QLibrary* library = new QLibrary("libopus.so");
typedef const char* (*MyPrototype)();
MyPrototype myFunction = (MyPrototype) library->resolve("opus_get_version_string");
qDebug() << myFunction();
qDebug() << opus_get_version_string();
The program compiles and deploys fine but when run on the emulator it errors out straight away as it is looking for the wrong version of the library.
E/AndroidRuntime(13463): FATAL EXCEPTION: main
E/AndroidRuntime(13463): Process: org.qtproject.example.AndroidUI, PID: 13463
E/AndroidRuntime(13463): java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "libopus.so.0" needed by "libAndroidUI.so"; caused by library "libopus.so.0" not found
QtCreator has in fact included the library in the apk but it choose just libopus.so hence why it could not find libopus.so.0
In the lib directory I linked to it has the following files
lrwxrwxrwx 1 stuart stuart 16 Jan 8 17:37 libopus.so -> libopus.so.0.5.0
lrwxrwxrwx 1 stuart stuart 16 Jan 8 17:37 libopus.so.0 -> libopus.so.0.5.0
-rwxr-xr-x 1 stuart stuart 1170652 Jan 8 17:37 libopus.so.0.5.0
libopus.so and libopus.so.0 are just symlinks to libopus.so.0.5.0. QtCreator has correctly copied the file into the apk not the symlink but the referencing is wrong.
I know the library is fine as if I comment out the LIBS stuff in the pro file and the function call and use QLibrary then it works and resolves and I get the expected output from the function call.
Using QLibrary could be a work around in the meantime but is a bit clunky due to the typedefs and as the library is bundled there is no need for the dynamic loading.
Any better workarounds until this bug is fixed?