Qt5 QGeoPositionInfoSource :: createDefaultSource()在Android 5.0上崩溃 [英] Qt5 QGeoPositionInfoSource::createDefaultSource() crashes on Android 5.0

查看:304
本文介绍了Qt5 QGeoPositionInfoSource :: createDefaultSource()在Android 5.0上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发用于Android的Qt5应用程序(使用CMake!),当前我正在尝试使用Qt的QGeoPositionInfoSource读取位置数据. 到目前为止,我所有的应用程序都运行良好,但是当我运行

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);

应用程序立即崩溃,并且logcat给我:

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

我使用了最近的三个Android NDK和Qt的多个版本(从5.6到5.9)-都具有相同的结果,所以我认为我在系统上做错了事.

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.

我的AndroidManifest.xml包含以下几行:

<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?

更新:

我一直在追溯调用堆栈的最上一行:

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

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

,我发现jnipositioning.cpp中的以下行会导致崩溃:

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

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

所以新的问题是:什么会使javavm->GetEnv()(在jni.h中声明)崩溃?

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

另一个更新:

jpo38 指出,使用qmake进行编译会生成不会崩溃的Android应用.我已经建立了一个 github项目来演示此行为.

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.

现在的问题是:用CMake和qmake配置的应用程序有什么区别?

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

推荐答案

这显然效果很好:

TestGeo.pro:

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();
}

程序输出无崩溃:

Creating
Created

请注意,我没有在项目中添加任何AndroidManifest.xml文件.无论启用还是禁用本地化",它都可以工作.

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

我正在使用Android 5.1(armeabi-v7a)在Nexus 6上使用Android-22目标进行部署.使用Qt 5.6(GCC 4.9).使用NDK r11b.

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.

您的设置一定有问题.

执行此设置,生成有效的apk.然后提取该工作APK和失败的APK的内容.通过检查差异(缺少库,文件,不同清单...),您可以确定CMake构建和部署环境出了什么问题,以后再进行修复(可能是通过手动复制CMake项目中丢失的文件)!

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)!

在您的情况下,缺少对Qt定位库的引用.只需将它们正确添加到您的AndroidManifest.xml:

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"/>

这篇关于Qt5 QGeoPositionInfoSource :: createDefaultSource()在Android 5.0上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆