Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-68813

UnsatisfiedLinkError when manually registering functions via JNI_OnLoad

    XMLWordPrintable

    Details

    • Platform/s:
      Android
    • Commits:
      3c74042c3db8c68e47ed1f0c2ecd4d39a2d84912 (qt/qtbase/5.12)

      Description

      I have an Android application which uses some JNI to communicate between my Java and C++ classes. The JNI_OnLoad function looks something like this:

      JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void */* reserved */)
      {
        qDebug() << "starting to register functions";
        JNIEnv *env;
        if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK)
        {
          return JNI_ERR;
        }
        jclass nativeClass = env->FindClass("com/example/myapp/MainActivity");
        if (!nativeClass) return JNI_ERR;
        if (env->RegisterNatives(nativeClass, mainActivityMethods, sizeof(mainActivityMethods) / sizeof(mainActivityMethods[0])) < 0)
        {
          return JNI_ERR;
        }
        qDebug() << "registered all functions!";
        return JNI_VERSION_1_6;
      }
      

      It is contained in a file which is definitely listed as a source file in the .pro file. However, the debug statements are never printed out and I get

      java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String 
      com.example.myapp.MainActivity.foo() 
      (tried Java_com_example_myapp_MainActivity_foo
      and Java_com_example_myapp_MainActivity_foo__)
      

      I did not use to get this error before I upgraded to 5.11. Everything was working fine previously.

      It is, however, worth noting that I also did a "VCS refresh" in the sense that I had to pull all the files from the repository into a fresh directory because the old one was deleted. This could potentially be a factor, though I don't think so.

       

      I was able to manually resolve the error by adding a call to `System.loadLibrary("MyApp")` However, I was under the impression this was not supposed to be necessary. Therefore I believe it is a bug.

        Attachments

          Issue Links

          For Gerrit Dashboard: QTBUG-68813
          # Subject Branch Project Status CR V

            Activity

              People

              • Assignee:
                taipan BogDan Vatra
                Reporter:
                jonmcclung Jon McClung
              • Votes:
                18 Vote for this issue
                Watchers:
                30 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes