13

I'm developing a Qt5 application for Android (with CMake!) and currently I'm trying to read location data using Qt's QGeoPositionInfoSource. All of my application is doing fine so far but when I run

auto source = QGeoPositionInfoSource::createDefaultSource(this);

The application crashes immediately and logcat gives me:

I/__log_qt(  422): (II) dpw_qt5:    <last output from my app>
F/libc    (  422): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 797 (QtThread)
I/DEBUG   (  333): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (  333): Build fingerprint: 'samsung/trltexx/trlte:5.0.1/LRX22C/N910FXXU1BOE3:user/release-keys'
I/DEBUG   (  333): Revision: '12'
I/DEBUG   (  333): ABI: 'arm'
I/DEBUG   (  333): pid: 422, tid: 797, name: QtThread  >>> org.qtproject.DPW <<<
I/DEBUG   (  333): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
I/DEBUG   (  333):     r0 00000000  r1 9d2bedf8  r2 00010006  r3 be7eb61d
I/DEBUG   (  333):     r4 9d2bedf4  r5 9d2bedf8  r6 00000000  r7 9cffa030
I/DEBUG   (  333):     r8 9d2bedf4  r9 afd04388  sl 00000001  fp 9d2bf8dc
I/DEBUG   (  333):     ip 9cff9e80  sp 9d2bedd0  lr 9cff49b7  pc 9cff612e  cpsr 60070030
I/DEBUG   (  333): 
I/DEBUG   (  333): backtrace:
I/DEBUG   (  333):     #00 pc 0000512e  /data/data/org.qtproject.DPW/qt-reserved-files/plugins/position/libqtposition_android.so
I/DEBUG   (  333):     #01 pc 000039b3  /data/data/org.qtproject.DPW/qt-reserved-files/plugins/position/libqtposition_android.so

I've used the last three Android NDKs and several versions of Qt from 5.6 to 5.9 - all with the same result so I think I'm doing something wrong systematically.

My AndroidManifest.xml contains the following lines:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Do you have any idea for me where I can start to investigate?

Update:

I've been tracing back the top most line of the call stack:

I/DEBUG   (  333):     #00 pc 0000512e  /data/data/org.qtproject.DPW

and I found out that the following line inside jnipositioning.cpp causes the crash:

if (javaVM->GetEnv((void**)&jniEnv, JNI_VERSION_1_6) < 0) {

so the new question is: what can make javavm->GetEnv() (declared in jni.h) crash?

Another Update:

jpo38 pointed out that that building with qmake results in an Android app that does not crash. I've set up a github project demonstrating this behavior.

So the question is now: What's the difference between the apps being configured with CMake and qmake?

Community
  • 1
  • 1
frans
  • 6,905
  • 8
  • 40
  • 95
  • You should try to report a Qt bug. – jpo38 Feb 18 '17 at 07:49
  • I did: https://bugreports.qt.io/browse/QTBUG-59010 – frans Feb 18 '17 at 12:40
  • Good. Hopefully, you'll get an answer soon. I recommend that you post a MCVE to your Qt bug report. They look faster into problems when you do so. Good luck. – jpo38 Feb 18 '17 at 15:58
  • Have you tried to register a message handler (qInstallMessageHandler) ans see if you get a message before the system crashs? – jpo38 Feb 18 '17 at 16:18
  • Did you add `QT += positioning` inside your `.pro` file? Did you create an instance of `QGuiApplication` object? – Evgeny Feb 18 '17 at 18:31
  • @frans: Could you send the apk generated? I could then compare it with mine, maybe VS did not deploy your program correctly. – jpo38 Feb 24 '17 at 07:38
  • I've added some artifacts to the example project – frans Feb 24 '17 at 12:49
  • @frans: Did you try to extract and diff the content of the two generated apk files? – jpo38 Feb 24 '17 at 13:45
  • Yes, I'm on and maybe you gave the right hint - there are some suspicious libraries mentioned in the qmake-version of AndroidManifest.xml. When I merge these the CMake-App doesn't crash any more! Your answer does not contain this information yet but if you add it I'd like to give you the reward. – frans Feb 24 '17 at 14:13
  • @frans: Just added this at the end of my post. – jpo38 Feb 25 '17 at 07:47

1 Answers1

1

This apparently works pretty well:

TestGeo.pro:

QT += core gui
QT += positioning
QT += widgets

TARGET = TestGeo
TEMPLATE = app

SOURCES += main.cpp

CONFIG += mobility
MOBILITY = 

main.cpp:

#include <QMainWindow>
#include <QApplication>

#include <QGeoPositionInfoSource>
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QMainWindow w;

    qDebug() << "Creating";
    auto source = QGeoPositionInfoSource::createDefaultSource(&a);
    if ( source )
        qDebug() << "Created";
    else
        qDebug() << "NULL";

    w.show();

    return a.exec();
}

Program outputs with no crash:

Creating
Created

Note that I added no AndroidManifest.xml file to the project. It works both with "Localisation" enabled or disabled.

I'm deploying with Android-22 target on Nexus 6 with Android 5.1 (armeabi-v7a). Using Qt 5.6 (GCC 4.9). Using NDK r11b.

There must be something wrong with your setup.

So do this setup, generate the working apk. Then extract the content of this working apk and your failing apk. By checking the differences (missing libraries, files, different manifest....), you may identify what's wrong with your CMake build and deployment environment and later fix it (possibly by manually copying missing files in the CMake project)!

In your case the references to Qt's positioning libraries are missing. Just add them correctly to your AndroidManifest.xml:

<meta-data android:name="android.app.load_local_libs" android:value="plugins/platforms/android/libqtforandroid.so:plugins/position/libqtposition_android.so"/>
<meta-data android:name="android.app.load_local_jars" android:value="jar/QtAndroid.jar:jar/QtAndroidAccessibility.jar:jar/QtAndroid-bundled.jar:jar/QtAndroidAccessibility-bundled.jar:jar/QtPositioning.jar:jar/QtPositioning-bundled.jar"/>
<meta-data android:name="android.app.static_init_classes" android:value="org.qtproject.qt5.android.positioning.QtPositioning:org.qtproject.qt5.android.positioning.QtPositioning"/>
frans
  • 6,905
  • 8
  • 40
  • 95
jpo38
  • 19,174
  • 7
  • 62
  • 118
  • I have looked at his example inside bugreport. He uses CMake and VS to build his project. – Evgeny Feb 23 '17 at 20:00
  • One should start from a working solution (QtCreator, simple .pro, basic program) and then track what's different in a more complex solution (VS, CMake...) to see what causes the crash...Maybe VS does not deploy the program correctly – jpo38 Feb 24 '17 at 07:38
  • Well - I'm using CMake but not VS. I'll ty jpo's approach - turning a `qmake` project into a CMake project.. – frans Feb 24 '17 at 09:41
  • I've set up a github project for this: https://github.com/frans-fuerst/ShowQt5Location-android-cmake-qmake.git Can you just paste me a line showing how to configure a `qmake` project on command line providing the location to Qt5 and NDK? I looked around a bit but did not find a no brainer :) – frans Feb 24 '17 at 10:07
  • @frans: You don't need all that, just open the .pro file in QtCreator. You don't need CMake for such a simple project. – jpo38 Feb 24 '17 at 10:49