Important: Please read the Qt Code of Conduct -

Load external JAR library and FindClass

  • 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:

    2. I put this in the AndroidManifest.xml

      <meta-data android:name="" 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,

    [edit: added missing coding tags @ SGaist]

  • 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.


    [Thanks SGaist por the correction]

Log in to reply