使用Qt lib与本机JNI Android应用程序时出现QNetwork错误

Ale*_*kov 6 c++ java java-native-interface qt android

我有简单的Qt lib,它可以像这样生成http请求:

QNetworkAccessManager networkAccessManager;
QNetworkRequest request{QUrl("http://www.google.ru")};
QNetworkReply * reply = networkAccessManager.get(request);
...
Run Code Online (Sandbox Code Playgroud)

当我在Android设备上运行它(armeabi-v7a并且x86从Qt Creator中删除)时,一切正常.但我想与使用Android原生应用程序中NDKJNI.在这种情况下,它仅适用于armeabi-v7a 设备和Android 6.0版本.如果我在x86设备上使用此lib运行android应用程序,它将崩溃并显示下一条消息:

致命信号11(SIGSEGV)位于0x00000000(代码= 1),线程11830(itekllc.testjni)

它发生在我的Qt lib中的这行代码中:

QNetworkReply * reply = networkAccessManager.get(request);
Run Code Online (Sandbox Code Playgroud)

这是我communication.cpp在原生android项目中的文件:

#include <jni.h>
#include "QCoreApplication"
#include "testandroidthreadslib.h"

#ifndef _Included_com_navitekllc_testjni_CppWrapper
#define _Included_com_navitekllc_testjni_CppWrapper

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT void JNICALL
Java_com_navitekllc_testjni_CppWrapper_testNetwork(JNIEnv *env, jclass type) {
    TestAndroidThreadsLib testLib;
    testLib.run();
}

#ifdef __cplusplus
}
#endif
#endif
Run Code Online (Sandbox Code Playgroud)

这是我的.java调用.cpp函数文件:

public class CppWrapper {
    public static native void testNetwork();

    static {
        System.loadLibrary("communication");
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的build.gradleexdlemental gradle文件:

apply plugin: 'com.android.model.application'

model {

    repositories {
        libs(PrebuiltLibraries) {
            QtStaticLibrary {
                headers.srcDir file("..PathToLib/TestAndroidThreadsLib").absolutePath
                binaries.withType(StaticLibraryBinary) {
                    def myStaticLibPath = "src/main/jniLibs/${targetPlatform.getName()}/libTestAndroidThreadsLib.a"
                    staticLibraryFile = file("${myStaticLibPath}")
                }
            }
            QCoreSharedLibrary {
                binaries.withType(SharedLibraryBinary) {
                    def coreLibPath = "src/main/jniLibs/${targetPlatform.getName()}/libQt5Core.so"
                    sharedLibraryFile = file("${coreLibPath}")
                }
            }
            QNetSharedLibrary {
                binaries.withType(SharedLibraryBinary) {
                    def networkLibPath = "src/main/jniLibs/${targetPlatform.getName()}/libQt5Network.so"
                    sharedLibraryFile = file("${networkLibPath}")
                }
            }
        }
    }

    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.3"

        defaultConfig {
            minSdkVersion.apiLevel 18
            targetSdkVersion.apiLevel 21
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles.add(file('proguard-rules.pro'))
            }
        }

        sources {
            main {
                jni {
                    dependencies {
                        library "QtStaticLibrary" linkage "static"
                        library "QCoreSharedLibrary" linkage "shared"
                        library "QNetSharedLibrary" linkage "shared"
                    }
                }
            }
        }

        ndk {
            moduleName = "communication"
            cppFlags.add("-std=c++11")
            stl "gnustl_shared"

            cppFlags.add('-I' + file("/Volumes/Transcend/Qt/5.7/android_armv7/include").absolutePath)
            cppFlags.add('-I' + file("/Volumes/Transcend/Qt/5.7/android_armv7/include/QtCore").absolutePath)

            abiFilters.addAll([
                    "x86",
                    "armeabi-v7a"
            ])
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'

    compile 'com.android.support:appcompat-v7:24.2.1'
}
Run Code Online (Sandbox Code Playgroud)

如果有人告诉我做错了什么以及为什么这行代码中的错误会很棒:

QNetworkReply * reply = networkAccessManager.get(request);
Run Code Online (Sandbox Code Playgroud)

仅在x86设备和Android版本低于6.0的设备上发生,并且仅来自原生Android项目(来自QtCreator,所有工作都没有错误).感谢帮助.