skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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


  2. I’m currently facing a similar problem as described above. Could you please provide detail solution to resolve this problem? Thanks.

    This is file CMakeLists.txt

    cmake_minimum_required(VERSION 3.22.1)
    project("check-libs")
    add_library(lib_track SHARED IMPORTED)
    set_target_properties(
            lib_track
            PROPERTIES IMPORTED_LOCATION
            ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libtrack.so
    )
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
    add_library(
            check-libs SHARED
            check_jni.cpp)
    target_include_directories(check-libs PRIVATE
            ${CMAKE_CURRENT_SOURCE_DIR}/include)
    find_library(
            log-lib
            log)
    target_link_libraries( 
            check-libs
            android
            lib_track
            ${log-lib})
    

    And build.gradle

    android {
        ...
        ndkVersion '25.1.8937393'
        defaultConfig {
            ...
            externalNativeBuild {
                cmake {
                    cppFlags "-std=c++11", "-fexceptions", "-frtti"
                    cFlags "-D__STDC_FORMAT_MACROS"
                    arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_static", "-DANDROID_ARM_NEON=TRUE", "-DANDROID_STL=c++_shared"
                    abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
                }
            }
        }
        ...
        externalNativeBuild {
            cmake {
                path file('src/main/cpp/CMakeLists.txt')
                version '3.22.1'
            }
        }
        sourceSets {
            main {
                jniLibs.srcDirs = ['jniLibs']
    
            }
        }
    }
    
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search