Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

java.lang.ClassNotFoundException with Android 6



  • Hi all,

    I have a strange problem with Qt 5.12.7 for Android ARM.
    I am developing an App which includes an Activity and 2 background services.
    I also have plugin system to extend one of this background services, and some of them use JNI / Java code.

    All works as expected with Android 7.0 devices (and upper) but with Android 6.0, I've got following errors:

    System.err: java.lang.ClassNotFoundException: Didn't find class "com.geocept.mobilecore.AndroidGPS" on path: DexPathList[[],nativeLibraryDirectories=[/vendor/lib, /system/lib]]: com.geocept.navdispatchmobile:mcore
    System.err: 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56): com.geocept.navdispatchmobile:mcore
    System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:511): com.geocept.navdispatchmobile:mcore
    System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:469): com.geocept.navdispatchmobile:mcore
    System.err: 	at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method): com.geocept.navdispatchmobile:mcore
    System.err: 	at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:374): com.geocept.navdispatchmobile:mcore
    System.err: 	at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61): com.geocept.navdispatchmobile:mcore
    System.err: 	at java.lang.Thread.run(Thread.java:818): com.geocept.navdispatchmobile:mcore
    

    To load the Java class I use something like this:

    m_jni =  QAndroidJniObject(
                  "com/geocept/mobilecore/AndroidGPS",
                  "(Landroid/content/Context;)V",
                  QtAndroid::androidContext().object<jobject>()
                  );
    
    if(m_jni.isValid())
    {
        if(JniMethods != Q_NULLPTR && methodCount > 0)
        {
            QAndroidJniEnvironment JniEnv;
            jclass ObjectClass;
            ObjectClass = JniEnv->GetObjectClass(m_jni.object<jobject>());
            JniEnv->RegisterNatives(ObjectClass, JniMethods, methodCount);
            JniEnv->DeleteLocalRef(ObjectClass);
        }
    }
    

    Any ideas why Android 6 don't find java class in APK but Android 7 does?



  • I reply to myself, I found the problem.
    I am using OnNmeaMessageListener in my Java class, which is only available with Android 7 and upper (API 24).

    I think I have to rework my java code to support older Android API level :(


Log in to reply