From 771cfca2ab07327016e168b7bf8c366835a7e85b Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 10 Apr 2024 13:35:25 +0200 Subject: [PATCH] Android: don't call JNI_OnLoad for libraries opened with QLibrary JNI_OnLoad gets called automatically by the JVM when it loads a shared library. A native library that is loaded by native code shouldn't have it's JNI_OnLoad entry point function called, as that would indicate that the plugin is loaded by the JVM, which it is not. If framework or application code requires that function to be called (and wants to perform error handling, such as closing the library again if the function returns JNI_ERR), then that can and should be done explicitly. [ChangeLog][Android][QLibrary] Loading a shared library with QLibrary no longer implicily calls a JNI_OnLoad implementation. Fixes: QTBUG-92007 Change-Id: I9aa71ec73b950029e0ae1be7d54e1c8576f356ab Reviewed-by: Assam Boudjelthia (cherry picked from commit 359df32300f5472f2fddbc83c3fe0851b5547ff6) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/plugin/qlibrary_unix.cpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/corelib/plugin/qlibrary_unix.cpp b/src/corelib/plugin/qlibrary_unix.cpp index 03f6eb8d331..1ad3a1f7217 100644 --- a/src/corelib/plugin/qlibrary_unix.cpp +++ b/src/corelib/plugin/qlibrary_unix.cpp @@ -207,14 +207,6 @@ bool QLibraryPrivate::load_sys() auto attemptFromBundle = attempt; hnd = dlopen(QFile::encodeName(attemptFromBundle.replace(u'/', u'_')), dlFlags); } - if (hnd) { - using JniOnLoadPtr = jint (*)(JavaVM *vm, void *reserved); - JniOnLoadPtr jniOnLoad = reinterpret_cast(dlsym(hnd, "JNI_OnLoad")); - if (jniOnLoad && jniOnLoad(QJniEnvironment::javaVM(), nullptr) == JNI_ERR) { - dlclose(hnd); - hnd = nullptr; - } - } #endif if (!hnd && fileName.startsWith(u'/') && QFile::exists(attempt)) {