【发布时间】:2021-07-14 04:03:45
【问题描述】:
我正在使用 Android NDK 构建本机应用程序。它依赖于各种共享对象 (.so)。我已将它们添加到 CMakeLists 中的应用程序中,如下所示:
add_library(bluetooth SHARED IMPORTED)
/home/stoic/fluoride/bt/output_dir/out/Default/lib/libbluetooth.so)
set_target_properties(bluetooth PROPERTIES IMPORTED_LOCATION /home/stoic/lib-bluetooth-x86-64/libbluetooth.so)
add_library(chrome SHARED IMPORTED)
set_target_properties(chrome PROPERTIES IMPORTED_LOCATION /home/stoic/lib-bluetooth-x86-64/libchrome.so)
add_library(grpc++ SHARED IMPORTED)
set_target_properties(grpc++ PROPERTIES IMPORTED_LOCATION /home/stoic/lib-bluetooth-x86-64/libgrpc++.so)
add_library(grpc_wrap SHARED IMPORTED)
set_target_properties(grpc_wrap PROPERTIES IMPORTED_LOCATION /home/stoic/lib-bluetooth-x86-64/libgrpc_wrap.so)
target_link_libraries(native-activity
android
native_app_glue
EGL
GLESv1_CM
log
bluetooth
chrome
grpc++
grpc_wrap
/home/stoic/lib-bluetooth-x86-64/libstatslog.so
/home/stoic/lib-bluetooth-x86-64/android.hardware.bluetooth.a2dp@1.0.so
)
我没有写整个 CMakeLists.txt,因为应用程序编译良好并且 apk 构建成功。
所有 .sos 加载正常,但 Android 运行时为 android.hardware.bluetooth.a2dp@1.0.so 提供此错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.native_activity, PID: 4230
java.lang.UnsatisfiedLinkError: Unable to load native library "/data/app/~~J6dVW4LGncsbvMxzwtgq7w==/com.example.native_activity-Je33LNoodZDV37TTvXSpEw==/lib/x86_64/libnative-activity.so": dlopen failed: library "android.hardware.bluetooth.a2dp@1.0.so" not found: needed by /data/app/~~J6dVW4LGncsbvMxzwtgq7w==/com.example.native_activity-Je33LNoodZDV37TTvXSpEw==/lib/x86_64/libnative-activity.so in namespace classloader-namespace
我检查了已构建应用程序的解压后的 apk,我看到 lib/x86_64 目录中存在 android.hardware.bluetooth.a2dp@1.0.so 以及其他 .sos。
ls lib/x86_64/
android.hardware.bluetooth.a2dp@1.0.so libbluetooth.so libchrome.so libgrpc++.so libgrpc_wrap.so libnative-activity.so libstatslog.so
有人知道我在做什么有什么问题吗?
【问题讨论】:
-
@1.0是什么?我认为 Android 不支持版本化共享库。参见例如stackoverflow.com/questions/11491065/… -
@Michael 感谢您的链接。它解决了这个问题。
标签: android bluetooth android-ndk runtime-error