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

How to solve a java.lang.ClassNotFoundException on a device, if the app works in the simulator?



  • I need to present my prototype next week but the app behaves different on the device than on the simulator:

    I use JNI to retrieve information about the installed apps for a launcher. This works pretty well in the simulator of a Nexus 5X API 27 but not on an Aquaris C developer device with Android 8.1:

    W System.err: java.lang.ClassNotFoundException: Didn't find class "com.myapp.launcher.worker.AppWorker" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /vendor/lib]]
    W System.err: 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
    W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    W System.err: 	at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method)
    W System.err: 	at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:387)
    W System.err: 	at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
    W System.err: 	at java.lang.Thread.run(Thread.java:764)
    

    I realized that two further things don't work:

    • The app icon, that I have defined in the Manifest file is not shown on the device.
    • The app doesn't behave like a launcher, although I defined the following intent filer:
    <intent-filter>
         <action android:name="android.intent.action.MAIN"/>
         <category android:name="android.intent.category.HOME"/>
         <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
    

    I'm quite lost.



  • Here is my solution:

    I have created a new app from the template of Qt Creator and compared it with the example project for Qt Android:

    I conclude, that I have to modify the .pro file. First of all I had to add the following line:

    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
    

    Then I had to replace DISTFILES, that is automatically added by Qt Creator, if I create a Java class:

    OTHER_FILES += \
        main.qml \
        android-sources/src/com/hello/android/Backend.java \
        android-sources/AndroidManifest.xml
    

    Finally I had to edit the AndroidManifest.xml, that I have copied from the exmaple project, in the text editor mode:

    <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="com.hello.android.Backend" android:label="Hello Android" android:screenOrientation="unspecified">
    

    The last step was not necessary in the project of my initial question.



  • I realized an additional problem, that might be related to this issue: Although I have defined an Android manifest file, its definitions are ignored on the device (not on the simulator). On the device, the app doesn't behave as a launcher and the custom app icon and name is not displayed in the grid of apps on the device.



  • I still can reproduce that issue. JNI works in the simulator, but not on the device. What is different? How can I solve the problem?

    W System.err: java.lang.ClassNotFoundException: Didn't find class "com.myapp.launcher.worker.AppWorker" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib]]
    W System.err: 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    W System.err: 	at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method)
    W System.err: 	at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:387)
    W System.err: 	at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
    W System.err: 	at java.lang.Thread.run(Thread.java:764)


  • Here is my solution:

    I have created a new app from the template of Qt Creator and compared it with the example project for Qt Android:

    I conclude, that I have to modify the .pro file. First of all I had to add the following line:

    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
    

    Then I had to replace DISTFILES, that is automatically added by Qt Creator, if I create a Java class:

    OTHER_FILES += \
        main.qml \
        android-sources/src/com/hello/android/Backend.java \
        android-sources/AndroidManifest.xml
    

    Finally I had to edit the AndroidManifest.xml, that I have copied from the exmaple project, in the text editor mode:

    <activity android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation" android:name="com.hello.android.Backend" android:label="Hello Android" android:screenOrientation="unspecified">
    

    The last step was not necessary in the project of my initial question.


Log in to reply