[Android-development] java.lang.ClassNotFoundException with Android 6

Fabrice Mousset | GEOCEPT GmbH fabrice.mousset at geocept.com
Tue Jun 30 07:59:02 CEST 2020


Hello,

I have posted this also on Qt Forum, but got no reply, perhaps to technic ☹
I try it here.

I have a strange problem with Qt 5.12.x 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 (and perhaps older), 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

The plugin is loaded with QPluginLoader

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;

        auto 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?
Is there something I am doing wrong?
I load the plugin at the beginning of the service process and in the main thread.

I also have other C++ classes which are using JNI in the same way as above, but those are part of the main project and loading them works fine (with the same code base).

For now, I am only need one type of plugin, so I could change it to move the plugin into main library (change plugin project into static library for example).
But this cannot not be the final solution.

Thanks for any suggestion.

BR

Fabrice Mousset


More information about the Android-development mailing list