Aegonis Aegonis - 6 months ago 23
Android Question

libQt5AndroidExtras.so not found

I am writing a mobile app in Qt that needs to make some platform-specific calls, like requesting battery level. So from the Qt level I am trying to make a call to the Android SDK level. From what I gathered on the internet, the following should do.

I made a small Java class with the code to be called:

// AndroidService.java
package path.to.java;

public class AndroidService {
public static int doSomething() {
System.out.println("Android says hi");
return 1;
}
}


Next, in my Cpp code, I make a call to this using Qt's Android JNI library:

// androidservice.cpp
#include <QtAndroidExtras>

void doSomething() {
QAndroidJniObject::callStaticMethod<int>("path.to.java.AndroidService", "doSomething");
}


I call this in my main function.

Lastly, I added the following to my .pro file:

// project.pro
android {
QT += androidextras
SOURCES += mobileservice/androidservice.cpp
OTHER_FILES += mobileservice/android/src/path/to/java/AndroidService.java
ANDROID_PACKAGE_SOURCE_DIR=$$_PRO_FILE_PWD_/mobileservice/android
}


Upon compilation, this builds without error. However, when running the app, I get a crash with the following stack trace:

E/AndroidRuntime( 7184): java.lang.UnsatisfiedLinkError: dlopen failed: library "libQt5AndroidExtras.so" not found
E/AndroidRuntime( 7184): at java.lang.Runtime.loadLibrary(Runtime.java:371)
E/AndroidRuntime( 7184): at java.lang.System.loadLibrary(System.java:988)
E/AndroidRuntime( 7184): at org.qtproject.qt5.android.bindings.QtActivity.loadApplication(QtActivity.java:252)
E/AndroidRuntime( 7184): at org.qtproject.qt5.android.bindings.QtActivity.startApp(QtActivity.java:655)
E/AndroidRuntime( 7184): at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:895)
E/AndroidRuntime( 7184): at android.app.Activity.performCreate(Activity.java:6500)
E/AndroidRuntime( 7184): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
E/AndroidRuntime( 7184): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3072)
E/AndroidRuntime( 7184): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3218)
E/AndroidRuntime( 7184): at android.app.ActivityThread.access$1000(ActivityThread.java:198)
E/AndroidRuntime( 7184): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1676)
E/AndroidRuntime( 7184): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 7184): at android.os.Looper.loop(Looper.java:145)
E/AndroidRuntime( 7184): at android.app.ActivityThread.main(ActivityThread.java:6837)
E/AndroidRuntime( 7184): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 7184): at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 7184): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
E/AndroidRuntime( 7184): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)


Despite adding the androidextras library to my .pro file, the app seems not to be able to find it. Am I missing something?

Answer

Okay, I think I found it. What I didn't mention is that my project consists of subprojects: project.pro is built first and then included by app.pro and by test.pro. In that case, apparently the statement

QT += androidextras

must be written in all applicable .pro files. Otherwise, qmake won't take it into account and the libraries won't be included during compilation.

Thanks all for your input.