android-studioshared-librariesndk-build

dlopen failed for prebuilt so file at Android Studio


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?


Solution

  • 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.
      <uses-native-library android:name="libb.so" />

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