I have a simple Qt lib that makes an HTTP request as follows:
QNetworkAccessManager networkAccessManager; QNetworkRequest request{QUrl("http://www.google.ru")}; QNetworkReply * reply = networkAccessManager.get(request); ...
Everything works fine when I run it on Android devices ( armeabi-v7a and x86 ) without conversion from Qt Creator. But I want to use it inside my own Android application with NDK and JNI . In this case, it only works on armeabi-v7a and with Android from version 6.0. If I run an Android app with this library on an x86 device, it crashes with the following message:
Fatal signal 11 (SIGSEGV) at 0x00000000 (code = 1), stream 11830 (Itekllc.testjni)
And this happens on this line of code inside my Qt lib:
QNetworkReply * reply = networkAccessManager.get(request);
This is my communication.cpp file in my own Android project:
#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
This is my .java file to call the .cpp function:
public class CppWrapper { public static native void testNetwork(); static { System.loadLibrary("communication"); } }
This is my build.gradle experimental gradle file:
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' }
It would be great if someone says what I'm doing wrong and why the error is in this line of code:
QNetworkReply * reply = networkAccessManager.get(request);
happens only on x86 devices and on devices with Android version less than 6.0 and only from their own Android project (from QtCreator everything works without errors). Thanks for the help.