I want to add another lib into android-ndk hello-libs example.
In CMakeLists.txt
, I add:
# this is from the hello-libs sample code
add_library(lib_gperf SHARED IMPORTED)
set_target_properties(lib_gperf PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libgperf.so)
########## I add this after the sample code: ###########
add_library(lib_py SHARED IMPORTED)
set_target_properties(lib_py PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/gperf/lib/${ANDROID_ABI}/libpython.so)
And this:
target_link_libraries(
hello-libs
android
lib_gperf
#### this line ######
lib_py
log)
And copy libpython.so
in the directory where libgperf.so
located:
Also copy the python headers into the include directory:
When I click the run button:
java.lang.UnsatisfiedLinkError: dlopen failed: library "/Users/finn/Downloads/hello-libs/app/src/main/cpp/../../../../distribution/gperf/lib/arm64-v8a/libpython.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
at java.lang.System.loadLibrary(System.java:1657)
at com.example.hellolibs.MainActivity.<clinit>(MainActivity.java:36)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2747)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1620)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:173)
at android.app.ActivityThread.main(ActivityThread.java:6698)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)
The path exists in my computer, but why the apk use my computer path, but not the android device path?
And I use the Android device file explorer, the lib is in the directory:
Then how can I make the apk use the right path?
Or I miss something to add?