dlopen在Android Studio中预构建的so文件上失败

huangapple go评论54阅读模式
英文:

dlopen failed for prebuilt so file at Android Studio

问题

我正在使用Android Studio制作一个应用程序。
尝试使用外部预构建的so文件时出现问题。
main/cpp/CMakeLists.txt声明如下。

add_library(ace SHARED ace.cpp)
add_library(banana SHARED IMPORTED)
set_target_properties(banana PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libbanana.so)
target_link_libraries(ace banana)

然后我得到了以下错误。

java.lang.UnsatisfiedLinkError: dlopen失败:找不到库“app/src/main/cpp/../jniLibs/arm64-v8a/libbanana.so”:由/data/app/~~H6athrEZA==/com.test1T_dd6A==/base.apk!/lib/arm64-v8a/ace.so所需。

我将libbanana.so放在了main/jniLibs/arm64-v8a目录下。
我还设置了以下build.gradle。

ndk {
   abiFilters 'arm64-v8a'
}

在以下路径中也确认了libbanana.so。

build->分析APK->文件->lib->arm64-v8a。

如果我删除与libbanana相关的内容,它可以工作,但是
我的目标是使用预构建的libbanana.so。
有人知道问题是什么吗?

我添加了一些测试。
我添加了另一个so文件,但没有错误。
如何使so文件正常工作?

英文:

I am making an app with android studio.
There is a problem trying to use external prebuilt so.
main/cpp/CMakeLists.txt was declared as follows.

add_library(ace SHARED ace.cpp)
add_library(banana SHARED IMPORTED)
set_target_properties(banana PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libbanana.so)
target_link_libraries(ace banana)

And then I get the following error.

java.lang.UnsatisfiedLinkError: dlopen failed: library "app/src/main/cpp/../jniLibs/arm64-v8a/libbanana.so" not found: needed by /data/app/~~H6athrEZA==/com.test1T_dd6A==/base.apk!/lib/arm64-v8a/ace.so in namespace

I put the libbanana.so to the main/jniLibs/arm64-v8a.
I also set the build.gradle below.

ndk {
   abiFilters 'arm64-v8a'
}

Libbanana.so was also confirmed in the path below.

build->Analyze APK-> File->lib->arm64-v8a.

If I remove the contents related to libbanana, it works, but
My goal is to use prebuilt libbanana.so.
Does anyone know what the problem is?

I added a few tests.
I put in another so file, but there is no error.
how to make the so file is normal?

答案1

得分: 0

  1. 尝试了3次后解决了。

  2. 如果在想要使用的"A so文件"中使用了另一个"B so文件",则必须在AndroidManifest.xml中指定"B so文件"已经存在于设备中。
    <uses-native-library android:name="libb.so" />

  3. 将so文件添加到/vendor/etc/public.libraries.txt。

英文:

It was resolved after 3 attempts.

  1. Change the build method of so file to NDK

  2. If another 'B so file' is used in the 'A so file' you want to use, you must specify in AndroidManifest.xml that the 'B so file' already exists in the device.<br>
    &lt;uses-native-library android:name=&quot;libb.so&quot; /&gt;

  3. Add so file to /vendor/etc/public.libraries.txt

huangapple
  • 本文由 发表于 2023年6月16日 07:48:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76486139.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定