Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. error: undefined reference to `ANativeWindow_fromSurface`
Forum Updated to NodeBB v4.3 + New Features

error: undefined reference to `ANativeWindow_fromSurface`

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SamuelYeh
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • FerniF Offline
      FerniF Offline
      Ferni
      wrote on last edited by
      #2

      I found a similar java code vulkan post and I had no problem. After added the right includes everything worked fine.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SamuelYeh
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • FerniF Offline
          FerniF Offline
          Ferni
          wrote on last edited by
          #4

          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
          
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved