QAndroidJniObject::callStaticMethod got SIGSEGV

  • My code is like this:

    void MainClass::installApk(QString apkFile)
        QAndroidJniObject apkPath = QAndroidJniObject::fromString(apkFile);
        QAndroidJniObject activity = QtAndroid::androidActivity();
        QAndroidJniObject::callStaticMethod<void>("per.pqy.Extra", "installApk", "(Lorg/qtproject/qt5/android/bindings/QtActivity;Ljava/lang/String;)V",
                                                  activity.object<jobject>(), apkPath.object<jstring>());
    package per.pqy;
    import android.content.Context;
    import android.content.Intent;
    public class Extra
    	public Extra(){}
            public static void installApk(QtActivity activity, String apkFile)
    		Intent intent = new Intent(Intent.ACTION_VIEW);  
    		final Uri apkuri = Uri.fromFile(new File(apkFile));  
    		intent.setDataAndType(apkuri, "application/");  

    When the function "void MainClass::installApk(QString apkFile)" is executed ,Qt app crashs with SIGSEGV. How to solve? Thanks.

  • When I change
    <meta-data android:name="" android:value="true"/>
    <meta-data android:name="" android:value="false"/>
    the app doesn't crash any more.

  • I haven't touched the JNI/Android and Qt yet though hopefully I will this month. But I remember BogDan Vatra saying anything that a call you make from C++ to Java will be on the Qt thread, thus you will need to move your code to the Android UI Thread, meaning all you probably have to do is refactor your code and wrap it around a Runnable and throw it at runOnUiThread. Point is, it will crash because some Android APIs needs to be called from the Android thread.

    call a Java method from C/C++ Qt thread. The Java method will be executed in Qt thread, so we we need a way to access Android APIs in Android UI thread.
    our Java method uses Activity.runOnUiThread to post a runnable on Android UI thread. This runnable will be executed by the Android event loop on Android UI thread.
    the runnable accesses the Android APIs from Android UI thread.

    Source of that snippet

    Take with a grain of salt. I have yet to touch the JNI, just recalling the blog post made since I have to work on it eventually.

  • i have called methods from Activity using the jni successfully without changing threads. though i did get a crash when i was using callObjectMethod instead of callMethod.

Log in to reply