UPDATE: Same problem happens when I try to create QAndroidJniObject from jclass. Class is successfully found but QAndroidJniObject is not created and app crash.
jclass cls = env->FindClass("com/example/MyLib/Person");
QAndroidJniObject p(cls);
This also fails:
QAndroidJniObject string = QAndroidJniObject::fromString("TESTSTRING");
I have simple example where I try to call Java function from C++ library in android application. First I am building: libMyLib.so, then I am creating AAR library which includes the libMyLib.so and then I am testing the AAR in new test android app project.
Inside my Qt library project for libMyLib.so, I have jniinterface.cpp and this is the function:
JNIEXPORT void JNICALL Java_com_example_MyLib_LibraryClass_personTest(JNIEnv*, jobject, jobject person)
{
qDebug() << "C++ lib _________ Creating now QAndroidJniObject";
QAndroidJniObject p(person);
p.callMethod<void>("printPersonInfo", "(I)V", 29);
}
After libMyLib.so is built successfully, I am copying it in my AAR android project in My_AAR_project\app\src\main\jniLibs\x86\libMyLib.so
In this My_AAR_project I have two simple classes: LibraryClass.java
public class LibraryClass {
public native void personTest(Person person);
public void testThePerson() {
Person p = new Person();
personTest(p);
}
static {
System.loadLibrary("MyLib");
}
}
And the other class is simple Person.java class:
public class Person
{
public Person() {}
public static void printPersonInfo(int n)
{
System.out.println("Called printPersonInfo " + " Name: John" + " age: " + n);
}
}
And now after I built successfully AAR lib I am including it in my test android app and I am calling:
LibraryClass test = new LibraryClass();
test.testThePerson();
And the app crash and the last output is before creation of QAndroidJniObject:
D/: C++ lib _________ Creating now QAndroidJniObject
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 19897 (ampleandroidapp), pid 19897 (ampleandroidapp)
Any help or hint what may be the problem? Or I am doing something wrong.
To simplify what I am trying to do:
- Create Person object on java side
- Pass the Person object to C++ lirary
- Call
printPersonInfofunction from C++ on the Person object that is received from java