From e6034a4740756334317ab2445b518a645930f4f4 Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Wed, 20 Jul 2016 14:56:01 +0300 Subject: Make sure JNI_OnLoad is not called more than once Since Android 5.0 Google introduce a nasty bug[1] which calls JNI_OnLoad more than once. Basically every time when a library is loaded JNI_OnLoad is called if found, but it calls *again* JNI_OnLoad of its .so dependencies! So, JNI_OnLoad of libQt5Core.so gets called may times, this is not a problem as long as it's called from Qt's java delegate class loader. The problem is that the application .so file *must* be called from default class loader to allow the user to find his custom Activity/Service stuff. [1] Workaround https://code.google.com/p/android/issues/detail?id=215069 Change-Id: Ia71209658ef56056b560018597608acf7cb0f9ea Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/corelib/kernel/qjnionload.cpp | 5 +++++ src/plugins/platforms/android/androidjnimain.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/corelib/kernel/qjnionload.cpp b/src/corelib/kernel/qjnionload.cpp index 0f7b4b69ef..3bfcf3e666 100644 --- a/src/corelib/kernel/qjnionload.cpp +++ b/src/corelib/kernel/qjnionload.cpp @@ -38,6 +38,11 @@ Q_CORE_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { Q_UNUSED(reserved) + static bool initialized = false; + if (initialized) + return JNI_VERSION_1_6; + initialized = true; + typedef union { JNIEnv *nenv; void *venv; diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index ac37e7bd92..671dad98b2 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -822,6 +822,11 @@ QT_END_NAMESPACE Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void */*reserved*/) { + static bool initialized = false; + if (initialized) + return JNI_VERSION_1_6; + initialized = true; + QT_USE_NAMESPACE typedef union { JNIEnv *nativeEnvironment; -- cgit v1.2.3