Qt for Android: Jni - Unfortunately app has stopped



  • Hi Everybody;
    I'm using Qt 5.7 for Android. I tried compiling a basic app for Andorid, but I saw Unfortunately app has stopped and app closed.
    AndroidClass.java:

    package com.test;
    
    public class AndroidClass
    {
      public static void work()
      {
        System.out.println("Java Code worked!");
      }
    }
    

    android.h:

    #ifndef ANDROID_H
    #define ANDROID_H
    
    #include <QObject>
    #include <QAndroidJniObject>
    #include <QDebug>
    #include <jni.h>
    
    class Android : public QObject
    {
      Q_OBJECT
    public:
      explicit Android(QObject *parent = 0);
      Q_INVOKABLE void work() const;
    
    signals:
    
    public slots:
    };
    
    #endif // ANDROID_H
    

    android.cpp

    #include "android.h"
    
    Android::Android(QObject *parent) : QObject(parent)
    {
    }
    
    void Android::work() const
    {
      /*****************This is work!************************************
      QAndroidJniObject::callStaticMethod<void>("com/test/AndroidClass",
                                                "work", "()V");
       *****************************************************************/
    
      // This part is not working:
    
      JNIEnv* env;
    
      jclass class_ = env->FindClass("com/test/AndroidClass");
      if (!class_)
      {
        qDebug() << "Class Not Found!\n";
      }
    
      jmethodID method_id = env->GetStaticMethodID(class_, "work", "()V");
      if (!method_id)
      {
        qDebug() << "Method ID Error!\n";
      }
    
      env->CallStaticVoidMethod(class_, method_id);
    }
    

    .pro File, I added:

    android: {
        QT += androidextras
        INCLUDEPATH += /home/username/Android/Sdk/ndk-bundle/platforms/android-19/arch-arm/usr/include/
        INCLUDEPATH += /home/username/Android/Sdk/ndk-bundle/platforms/android-19/arch-arm/usr/include/android
    }
    

    My console output:

    W/System.err(10313): java.lang.ClassNotFoundException: android.graphics.drawable.RippleDrawable
    W/System.err(10313):    at java.lang.Class.classForName(Native Method)
    W/System.err(10313):    at java.lang.Class.forName(Class.java:251)
    W/System.err(10313):    at java.lang.Class.forName(Class.java:216)
    W/System.err(10313):    at org.qtproject.qt5.android.ExtractStyle.getClass(ExtractStyle.java:395)
    W/System.err(10313):    at org.qtproject.qt5.android.ExtractStyle.<init>(ExtractStyle.java:98)
    W/System.err(10313):    at org.qtproject.qt5.android.QtActivityDelegate.loadApplication(QtActivityDelegate.java:512)
    W/System.err(10313):    at java.lang.reflect.Method.invokeNative(Native Method)
    W/System.err(10313):    at java.lang.reflect.Method.invoke(Method.java:515)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtLoader.loadApplication(QtLoader.java:237)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:647)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:181)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:269)
    W/System.err(10313):    at android.app.Activity.performCreate(Activity.java:5447)
    W/System.err(10313):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
    W/System.err(10313):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
    W/System.err(10313):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
    W/System.err(10313):    at android.app.ActivityThread.access$800(ActivityThread.java:166)
    W/System.err(10313):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
    W/System.err(10313):    at android.os.Handler.dispatchMessage(Handler.java:102)
    W/System.err(10313):    at android.os.Looper.loop(Looper.java:136)
    W/System.err(10313):    at android.app.ActivityThread.main(ActivityThread.java:5584)
    W/System.err(10313):    at java.lang.reflect.Method.invokeNative(Native Method)
    W/System.err(10313):    at java.lang.reflect.Method.invoke(Method.java:515)
    W/System.err(10313):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
    W/System.err(10313):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
    W/System.err(10313):    at dalvik.system.NativeStart.main(Native Method)
    W/System.err(10313): Caused by: java.lang.NoClassDefFoundError: android/graphics/drawable/RippleDrawable
    W/System.err(10313):    ... 26 more
    W/System.err(10313): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.graphics.drawable.RippleDrawable" on path: DexPathList[[zip file "/data/app/org.qtproject.example-8.apk"],nativeLibraryDirectories=[/data/app-lib/org.qtproject.example-8, /vendor/lib, /system/lib]]
    W/System.err(10313):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    W/System.err(10313):    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    W/System.err(10313):    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    W/System.err(10313):    ... 26 more
    W/System.err(10313): java.lang.ClassNotFoundException: android.graphics.drawable.AnimatedStateListDrawable
    W/System.err(10313):    at java.lang.Class.classForName(Native Method)
    W/System.err(10313):    at java.lang.Class.forName(Class.java:251)
    W/System.err(10313):    at java.lang.Class.forName(Class.java:216)
    W/System.err(10313):    at org.qtproject.qt5.android.ExtractStyle.getClass(ExtractStyle.java:395)
    W/System.err(10313):    at org.qtproject.qt5.android.ExtractStyle.<init>(ExtractStyle.java:99)
    W/System.err(10313):    at org.qtproject.qt5.android.QtActivityDelegate.loadApplication(QtActivityDelegate.java:512)
    W/System.err(10313):    at java.lang.reflect.Method.invokeNative(Native Method)
    W/System.err(10313):    at java.lang.reflect.Method.invoke(Method.java:515)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtLoader.loadApplication(QtLoader.java:237)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:647)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:181)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:269)
    W/System.err(10313):    at android.app.Activity.performCreate(Activity.java:5447)
    W/System.err(10313):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
    W/System.err(10313):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
    W/System.err(10313):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
    W/System.err(10313):    at android.app.ActivityThread.access$800(ActivityThread.java:166)
    W/System.err(10313):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
    W/System.err(10313):    at android.os.Handler.dispatchMessage(Handler.java:102)
    W/System.err(10313):    at android.os.Looper.loop(Looper.java:136)
    W/System.err(10313):    at android.app.ActivityThread.main(ActivityThread.java:5584)
    W/System.err(10313):    at java.lang.reflect.Method.invokeNative(Native Method)
    W/System.err(10313):    at java.lang.reflect.Method.invoke(Method.java:515)
    W/System.err(10313):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
    W/System.err(10313):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
    W/System.err(10313):    at dalvik.system.NativeStart.main(Native Method)
    W/System.err(10313): Caused by: java.lang.NoClassDefFoundError: android/graphics/drawable/AnimatedStateListDrawable
    W/System.err(10313):    ... 26 more
    W/System.err(10313): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.graphics.drawable.AnimatedStateListDrawable" on path: DexPathList[[zip file "/data/app/org.qtproject.example-8.apk"],nativeLibraryDirectories=[/data/app-lib/org.qtproject.example-8, /vendor/lib, /system/lib]]
    W/System.err(10313):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    W/System.err(10313):    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    W/System.err(10313):    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    W/System.err(10313):    ... 26 more
    W/System.err(10313): java.lang.ClassNotFoundException: android.graphics.drawable.VectorDrawable
    W/System.err(10313):    at java.lang.Class.classForName(Native Method)
    W/System.err(10313):    at java.lang.Class.forName(Class.java:251)
    W/System.err(10313):    at java.lang.Class.forName(Class.java:216)
    W/System.err(10313):    at org.qtproject.qt5.android.ExtractStyle.getClass(ExtractStyle.java:395)
    W/System.err(10313):    at org.qtproject.qt5.android.ExtractStyle.<init>(ExtractStyle.java:100)
    W/System.err(10313):    at org.qtproject.qt5.android.QtActivityDelegate.loadApplication(QtActivityDelegate.java:512)
    W/System.err(10313):    at java.lang.reflect.Method.invokeNative(Native Method)
    W/System.err(10313):    at java.lang.reflect.Method.invoke(Method.java:515)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtLoader.loadApplication(QtLoader.java:237)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtLoader.startApp(QtLoader.java:647)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtActivityLoader.onCreate(QtActivityLoader.java:181)
    W/System.err(10313):    at org.qtproject.qt5.android.bindings.QtActivity.onCreate(QtActivity.java:269)
    W/System.err(10313):    at android.app.Activity.performCreate(Activity.java:5447)
    W/System.err(10313):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
    W/System.err(10313):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2393)
    W/System.err(10313):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2493)
    W/System.err(10313):    at android.app.ActivityThread.access$800(ActivityThread.java:166)
    W/System.err(10313):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1283)
    W/System.err(10313):    at android.os.Handler.dispatchMessage(Handler.java:102)
    W/System.err(10313):    at android.os.Looper.loop(Looper.java:136)
    W/System.err(10313):    at android.app.ActivityThread.main(ActivityThread.java:5584)
    W/System.err(10313):    at java.lang.reflect.Method.invokeNative(Native Method)
    W/System.err(10313):    at java.lang.reflect.Method.invoke(Method.java:515)
    W/System.err(10313):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
    W/System.err(10313):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
    W/System.err(10313):    at dalvik.system.NativeStart.main(Native Method)
    W/System.err(10313): Caused by: java.lang.NoClassDefFoundError: android/graphics/drawable/VectorDrawable
    W/System.err(10313):    ... 26 more
    W/System.err(10313): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.graphics.drawable.VectorDrawable" on path: DexPathList[[zip file "/data/app/org.qtproject.example-8.apk"],nativeLibraryDirectories=[/data/app-lib/org.qtproject.example-8, /vendor/lib, /system/lib]]
    W/System.err(10313):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    W/System.err(10313):    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    W/System.err(10313):    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    W/System.err(10313):    ... 26 more
    W/ResourceType(10313): Skipping entry 0x1080892 in package table 0 because it is not complex!
    D/dalvikvm(10313): GC_CONCURRENT freed 7227K, 56% free 6322K/14364K, paused 2ms+4ms, total 38ms
    D/dalvikvm(10313): Trying to load lib /data/app-lib/org.qtproject.example-8/libQtQuick2_Android.so 0x41c0caf0
    D/        (10313): (null):0 ((null)): QML debugging is enabled. Only use this in a safe environment.
    D/dalvikvm(10313): Added shared lib /data/app-lib/org.qtproject.example-8/libQtQuick2_Android.so 0x41c0caf0
    D/dalvikvm(10313): No JNI_OnLoad found in /data/app-lib/org.qtproject.example-8/libQtQuick2_Android.so 0x41c0caf0, skipping init
    D/StatusBarManagerService(  591): semi p:10313,o:t
    D/OpenGLRenderer(10313): Enabling debug mode 0
    D/dalvikvm(10313): GC_CONCURRENT freed 1644K, 65% free 5114K/14364K, paused 2ms+2ms, total 25ms
    I/Timeline(10313): Timeline: Activity_idle id: android.os.BinderProxy@41c09008 time:54858979
    I/InputDispatcher(  591): Delivering touch to (10313): action: 0x0, toolType: 1
    I/InputDispatcher(  591): Delivering touch to (10313): action: 0x1, toolType: 1
    F/libc    (10313): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 10365 (project.example)
    I/DEBUG   (  163): pid: 10313, tid: 10365, name: project.example  >>> org.qtproject.example <<<
    I/DEBUG   (  163): !@dumpstate -k -t -z -d -o /data/log/dumpstate_app_native -m 10313
    D/CrashAnrDetector(  591): pid: 10313, tid: 10365, name: project.example  >>> org.qtproject.example <<<
    E/android.os.Debug(  591): !@Dumpstate > dumpstate -k -t -z -d -m 10313 -o /data/log/dumpstate_app_error
    
    
    "org.qtproject.example" terminated.
    

    I know, there is QtAndroidExtras module for Qt. But I want to use pure Jni for Android. Because I'm using jni other Android development platforms (Qt, C++ Builder). When I tried compile this app with QAndroidJniObject::callStaticMethod member function, I get Java Code worked! output, so, it is works. But when I tried compile this app with pure jni functions (jni.h header file), I see Unfortunately app has stopped and I get console output.

    AndroidClass.java directory: MyApp/android/src/com/test/AndroidClass.java
    AndroidClass.class directory (compiled with Javac): build-MyApp-Android_for_armeabi_v7a_GCC_4_9_Qt_5_7_0-Debug/com/test/AndroidClass.class and there is same file in build-MyApp-Android_for_armeabi_v7a_GCC_4_9_Qt_5_7_0-Debug/android-build/src/com/test/AndroidClass.class
    How can I work this app with pure jni? Thanks.


  • Moderators

    @Ibrahim You are dereferencing a dangling pointer:

    JNIEnv* env;
    jclass class_ = env->FindClass("com/test/AndroidClass");
    

    You did not assign a pointer to an instance of JNIEnv to env.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.