【问题标题】:cannot locate symbol "ANativeWindow_fromSurfaceTexture" referenced by无法找到引用的符号“ANativeWindow_fromSurfaceTexture”
【发布时间】:2022-01-18 14:08:13
【问题描述】:

执行应用程序发生异常

无法定位由

引用的符号“ANativeWindow_fromSurfaceTexture”
System.loadLibrary("aaa");

在aaa.so文件中使用了ANativeWindow_fromSurfaceTexture函数(错误)

但使用 ANativeWindow_fromSurface 函数(没问题)

我找到了 Android\Sdk\ndk-bundle\sysroot\usr\include\android\native_window_jni.h

#if __ANDROID_API__ >= 13
/**
 * Return the ANativeWindow associated with a Java SurfaceTexture object,
 * for interacting with it through native code.  This acquires a reference
 * on the ANativeWindow that is returned; be sure to use ANativeWindow_release()
 * when done with it so that it doesn't leak.
 */
ANativeWindow* ANativeWindow_fromSurfaceTexture(JNIEnv* env, jobject surfaceTexture);
#endif

我的 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "test.com.trytryNdk"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        ndk{
            ldLibs "log", "z", "m", "OpenMAXAL", "android"
        }

    externalNativeBuild {
        ndkBuild {
            arguments "APP_PLATFORM=android-16"
        }
    }
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
sourceSets {
    main {
        jniLibs.srcDirs = ['libs']
        jni.srcDirs = []
        }
    }
}

dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

【问题讨论】:

  • 这是什么设备?
  • 测试设备:Sony Z、华为、Nexus 7、Nexus 9 版本:Android 4.4、5.1、7
  • 我相信@fadden 不久前回答了这个问题:stackoverflow.com/a/24313036/192373
  • 呃。 API 不应该像这样被删除。我刚刚上传了从 NDK 中删除 decl 和符号的更改,因此这将是构建失败而不是运行时失败。

标签: android android-ndk


【解决方案1】:

首先,包含surface_texture.h

使用ASurfaceTexture_fromSurfaceTexture(JNIEnv *env, jobject surfacetexture) 获取ASurfaceTexture*

然后使用ASurfaceTexture_acquireANativeWindow(ASurfaceTexture *st)得到ANativeWindow*

确保在完成所有操作后释放它。 ASurfaceTexture_release(ASurfaceTexture *st)

参考:https://developer.android.google.cn/ndk/reference/group/surface-texture

【讨论】:

  • 这是在 api 级别 28 中引入的。在较低的 api 级别中不可用。
  • @UdaraWanasinghe 真的吗?抱歉,我不知道。
猜你喜欢
  • 2021-06-27
  • 1970-01-01
  • 1970-01-01
  • 2016-01-17
  • 2011-03-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-20
相关资源
最近更新 更多