简体   繁体   English

Android NDK共享库UnsatisfiedLinkError OpenGLESv2

[英]Android NDK Shared Library UnsatisfiedLinkError OpenGLESv2

I'm getting "cannot locate symbol" errors to OpenGLESv2 functions when I launch my app. 启动应用程序时,OpenGLESv2函数出现“无法定位符号”错误。

02-28 12:49:43.443: E/art(1258): dlopen("/data/app-lib/com.xxx.xxx-2/libmy_ndk.so", RTLD_LAZY) failed: dlopen failed: cannot locate symbol "glGenRenderbuffers" referenced by "libmy_ndk.so"...

The library structure is as follows: 库结构如下:

C++ Library compiled with toolchain -> libmy_ndk.so
JNI Code calls C++ Library -> libmy.so

If I put the OpenGL functions in the JNI code and discard the C++ library entirely, it works as expected. 如果我将OpenGL函数放入JNI代码中并完全丢弃C ++库,则它会按预期工作。 But for some reason it's not dynamically linking OpenGL at runtime if I'm using the prebuilt C++ shared library. 但是由于某种原因,如果我使用预构建的C ++共享库,它不会在运行时动态链接OpenGL。

My make file looks like this: 我的make文件如下所示:

include $(CLEAR_VARS)
LOCAL_CFLAGS := -std=gnu++11
LOCAL_MODULE := my_ndk
LOCAL_SRC_FILES := libmy_ndk.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_EXPORT_LDLIBS := -lGLESv2
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := my
LOCAL_CFLAGS := -std=gnu++11
LOCAL_SRC_FILES := ndk.cpp
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog -landroid -lz
LOCAL_SHARED_LIBRARIES := my_ndk
include $(BUILD_SHARED_LIBRARY)

I'm not getting any compile errors, and everything but the OpenGL functions work. 我没有遇到任何编译错误,除了OpenGL函数之外,其他所有东西都可以正常工作。 I tried using LOCAL_LDLIBS := -lGLESv2 for both the prebuilt and shared libraries, and then changed it to LOCAL_EXPORT_LDLIBS as shown above, and no combination of those seem to work either. 我尝试对预构建库和共享库都使用LOCAL_LDLIBS:= -lGLESv2,然后将其更改为LOCAL_EXPORT_LDLIBS,如上所示,但似乎也没有任何组合。

SOLUTION: 解:

The problem was the compilation of the C++ library with the toolchain. 问题是使用工具链编译C ++库。 The libGLESv2.so it was initially linking against was not the same version that was loaded on the device, which was causing the conflict when loading. 最初链接到的libGLESv2.so与设备上加载的版本不同,这导致加载时发生冲突。

There are different folders for different architecture, There is a high possibility that you have not provided your Native Libraries for a specific architecture that you are currently debugging on. 不同的体系结构有不同的文件夹,很可能您没有为当前正在调试的特定体系结构提供本机库。

在此处输入图片说明


Kindly copy your .so Libs in these folders aswell. 请将您的.so Libs也复制到这些文件夹中。
I hope this helps. 我希望这有帮助。

Edit: 编辑:
Please add the feature as required from the list below in your Manifest.xml file : 请根据需要从Manifest.xml文件的以下列表中添加功能:

<-- require OpenGL ES version 1.0 (default) -->
<uses-feature android:glEsVersion="0x00010000"/>

<-- require OpenGL ES version 1.1 -->
<uses-feature android:glEsVersion="0x00010001"/>

<-- require OpenGL ES version 2.0 -->
<uses-feature android:glEsVersion="0x00020000"/>

<-- require OpenGL ES version 3.0 -->
<uses-feature android:glEsVersion="0x00030000"/>

Dynamic Liner Library : 动态班轮库
Please go through This link : NDK OpenGL undefined reference to glVertexPointer 请通过以下链接: NDK OpenGL对glVertexPointer的未定义引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM