简体   繁体   中英

Cmake link wrong path of a pre built binary android

I'm trying to add python on my android app using PyBridge . I compiled libpython3.8.so using python-for-android Docker container for ABI arm64-v8a armeabi-v7a with no error. I successfully build a test apk using cmake for native library.

But when i run app on my phone I got this error

2022-01-29 14:09:42.066 23611-23611/com.manob.pythontest E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.manob.pythontest, PID: 23611
    java.lang.UnsatisfiedLinkError: dlopen failed: library "/Users/manobbiswas/AndroidStudioProjects/PythonTest/app/src/main/cpp/../libs/arm64-v8a/libpython3.8.so" not found: needed by /data/app/~~csjGY6aZ9p08Bug52yMA-Q==/com.manob.pythontest-IbjpbfFuiPALMmRIIt_C8A==/lib/arm64/libpythontest.so in namespace classloader-namespace 

In errorlog I find path of libpython3.8.so /Users/manobbiswas/AndroidStudioProjects/PythonTest/app/src/main/cpp/../libs/arm64-v8a/libpython3.8.so instade of /lib/arm64/libpython3.8.so

hear is CmakeList.txt

cmake_minimum_required(VERSION 3.10.2)
project("pythontest")
add_library(
        pythontest
        SHARED
        native-lib.cpp)

add_library(python3.8
        SHARED
        IMPORTED)

set_target_properties(python3.8
        PROPERTIES IMPORTED_LOCATION
        ${PROJECT_SOURCE_DIR}/../libs/${ANDROID_ABI}/libpython3.8.so )

include_directories(include/${ANDROID_ABI})

find_library(log-lib log)

target_link_libraries(pythontest python3.8 ${log-lib})

This error happens caused while building libpython3.8.so SONAME header wasn't set.

It can be verified by

readelf -a libpython3.8.so

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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