Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt for Android - undefined reference to ANativeWindow_fromSurface

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 used

QPlatformNativeInterface *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.

like image 644
SamuelYeh Avatar asked May 16 '26 06:05

SamuelYeh


1 Answers

I added LIBS += -landroid in *.pro file. So, it works.

like image 59
datakun Avatar answered May 18 '26 19:05

datakun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!