From 8b79fc4ee1c0510c13dc6f1494f37727e3f8c0cf Mon Sep 17 00:00:00 2001 From: BogDan Vatra Date: Wed, 20 Jul 2016 15:51:07 +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! [1] Workaround https://code.google.com/p/android/issues/detail?id=215069 Change-Id: I34728572bc279581b8c95c42c206ed104bfc09a5 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/plugins/sensors/android/src/androidjnisensors.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/plugins/sensors/android/src/androidjnisensors.cpp b/src/plugins/sensors/android/src/androidjnisensors.cpp index 98f408a9..ce69e757 100644 --- a/src/plugins/sensors/android/src/androidjnisensors.cpp +++ b/src/plugins/sensors/android/src/androidjnisensors.cpp @@ -241,6 +241,11 @@ static bool registerNatives(JNIEnv *env) Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*reserved*/) { + static bool initialized = false; + if (initialized) + return JNI_VERSION_1_6; + initialized = true; + typedef union { JNIEnv *nativeEnvironment; void *venv; -- cgit v1.2.3