Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to solve a java.lang.ClassNotFoundException on a device, if the app works in the simulator?

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

Scheduled Pinned Locked Moved Solved Mobile and Embedded
4 Posts 1 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    a.burks
    wrote on 15 Sept 2019, 01:19 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      a.burks
      wrote on 17 Jan 2020, 20:57 last edited by
      #4

      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        a.burks
        wrote on 23 Sept 2019, 11:52 last edited by
        #2

        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.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          a.burks
          wrote on 11 Jan 2020, 22:58 last edited by a.burks 1 Dec 2020, 00:14
          #3

          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)
          
          1 Reply Last reply
          0
          • A Offline
            A Offline
            a.burks
            wrote on 17 Jan 2020, 20:57 last edited by
            #4

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved