Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.3.1
-
None
-
Linux 64bits (XUbuntu)
Qt 5.3.1
Description
Hi,
The following pieces of code behave differently:
A. void test_a() // called from main function { QAndroidJniEnvironment jniEnv; jclass j_info_class = jniEnv->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”.
and
B. void test_b() // called from main function { if (QAndroidJniObject::isClassAvailable("xxx/yyy/zzz/MyClass")) { qDebug() << "Available"; } }
Prints “Available”
So, the Java class was found in test_b() but wasn't found in test_a().
Note: I need to use the test_a() code (FindClass) because I am using a shared library (I can not modify the code) that uses JNI that way.
These are the configuration steps I followed:
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: build-myProjectName-Platform-Debug/android-build/libs
2. I put this in the AndroidManifest.xml
<meta-data android:name=“android.app.load_local_jars” 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.
Regards,
Fernando.
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
Hi,
I have a legacy JAR (java code) and a legacy shared library (C++) that uses JNI to "talk with JAR".
I have the following example code:
A. jclass code_on_the_shared_library(JNIEnv* jni) { return jni->FindClass("xxx/yyy/zzz/MyClass"); } // ... void code_in_the_qt_executable() // called from main function { QAndroidJniEnvironment jniEnv; jclass j_info_class = function_on_the_shared_library(jniEnv); 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”.
On the other hand, I did the following test
B.
if (QAndroidJniObject::isClassAvailable("xxx/yyy/zzz/MyClass")) { qDebug() << "Available"; }
Prints “Available”
These are the configuration steps:
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: build-myProjectName-Platform-Debug/android-build/libs
2. I put this in the AndroidManifest.xml
<meta-data android:name=“android.app.load_local_jars” 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.
Thanks and regards,
Fernando.