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. Load external JAR library and FindClass
Forum Updated to NodeBB v4.3 + New Features

Load external JAR library and FindClass

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 1 Posters 2.2k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fpelliccioni
    wrote on last edited by
    #1

    Hi,

    I am trying to load an external JAR (java code) library into my Android App.

    I am following the following steps:

    1. I put the .jar file into android/libs directory.

      When I run in debug mode I could check that the JAR is copied into:
      build-myProjectName-Platform-Debug/android-build/libs

    2. I put this in the AndroidManifest.xml

      <meta-data android:name="android.app.load_local_jars" android:value="jar/QtAndroid.jar:jar/QtAndroidAccessibility.jar:jar/QtAndroid-bundled.jar:jar/QtAndroidAccessibility-bundled.jar:jar/myjar.jar"/>

       Note: The "jar/QtAndroid.jar:jar/QtAndroidAccessibility.jar:jar/QtAndroid-bundled.jar:jar/QtAndroidAccessibility-bundled.jar" part was copied from the original AndroidManifest.xml created by the QtCreator.
      
    3. I have the following code:
      @
      void test() // called from main function
      {
      QAndroidJniEnvironment jniEnv;
      JNIEnv* jni = jniEnv;
      jclass j_info_class = jni->FindClass("xxx/yyy/zzz/MyClass");

       if ( j_info_class ) {
           qDebug() << "j_info_class is valid";
       } else {
           qDebug() << "j_info_class is invalid";
       }
      

      }
      @

    The value of j_info_class is nullptr, printing "j_info_class is invalid".

    I can not find documentation with clear steps on how to do this.
    What I was doing was adding things I've found in different forums.

    What am I doing wrong?

    Thanks and regards,
    Fernando.

    [edit: added missing coding tags @ SGaist]

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fpelliccioni
      wrote on last edited by
      #2

      Note:

      Using the following code, the Java class was found.

      @
      if (QAndroidJniObject::isClassAvailable("xxx/yyy/zzz/MyClass")) {
      qDebug() << "Available";
      }
      @

      Prints "Available"

      That is, the configuration seems to be OK. That means that the problem seems to be in QAndroidJniEnvironment::FindClass.

      I need to use FindClass because I am using a shared library (I can not modify the code) that uses JNI that way.

      Regards,
      Fernando.

      [Thanks SGaist por the correction]

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fpelliccioni
        wrote on last edited by
        #3

        I submitted the following bug:

        https://bugreports.qt-project.org/browse/QTBUG-40494

        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