Unsolved error: undefined reference to `ANativeWindow_fromSurface`
-
hello.
I am a beginner of Qt,
I was trying to use Qt to make an Android application and used GStreamer(not QtGStreamer) to stream video through RTSP.
But when I usedQPlatformNativeInterface *nativeInterface = QApplication::platformNativeInterface(); jobject activity = (jobject)nativeInterface->nativeResourceForIntegration("QtActivity"); QAndroidJniEnvironment * qjniEnv; JNIEnv * jniEnv; JavaVM * jvm = qjniEnv->javaVM(); jvm->GetEnv(reinterpret_cast<void**>(&qjniEnv), JNI_VERSION_1_6); jvm->AttachCurrentThread(&jniEnv,NULL); jint r_id_content = QAndroidJniObject::getStaticField<jint>("android/R$id", "content"); QAndroidJniObject view = ((QAndroidJniObject) activity).callObjectMethod("findViewById", "(I)Landroid/view/View;", r_id_content); if (view.isValid()) { QAndroidJniObject child1 = view.callObjectMethod("getChildAt", "(I)Landroid/view/View;", 0); QAndroidJniObject child2 = child1.callObjectMethod("getChildAt", "(I)Landroid/view/View;", 0); if (child2.isValid()) { QAndroidJniObject sHolder = child2.callObjectMethod("getHolder","()Landroid/view/SurfaceHolder;"); if (sHolder.isValid()) { QAndroidJniObject theSurface = sHolder.callObjectMethod("getSurface","()Landroid/view/Surface;"); if (theSurface.isValid()) { ANativeWindow* awindow = ANativeWindow_fromSurface(jniEnv, theSurface.object()); qDebug() << "This is a ANativeWindow " << awindow; } } } else { qDebug() << "Views are not loaded yet or you are not in the Qt UI Thread"; } }
to get the ANativeWindow,
It got an error:undefined reference to 'ANativeWindow_fromSurface'
I have added
QT += androidextras
in .pro and
#include<android/native_window.h>
#include<android/native_window_jni.h>
in .cpp file, I don't know what else should I do.Is there anyone can help me to solve this problem?
Thanks. -
I found a similar java code vulkan post and I had no problem. After added the right includes everything worked fine.
-
Thanks for your reply,
but I thought that my problem occurred when linking the "android/native_window_jni.h" or something else.
Should I check my Android NDK? -
Hi @SamuelYeh , I didn't read your reply before. I think that you didn't add something like this in your .pro. I think that the error comes because you are not linking with libandroid.
LIBS += -L/opt/android-ndk-r12b/platforms/android-19/arch-arm/usr/lib -landroid