【发布时间】:2019-07-31 16:44:11
【问题描述】:
我想在android-ndk hello-libs 示例中添加另一个库。
在CMakeLists.txt,我添加:
# 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)
还有这个:
target_link_libraries(
hello-libs
android
lib_gperf
#### this line ######
lib_py
log)
并将libpython.so复制到libgperf.so所在的目录下:
同时将 python 头文件复制到包含目录中:
当我点击运行按钮时:
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)
路径存在于我的电脑中,但是为什么apk使用我的电脑路径,而不是android设备路径?
而我使用的是安卓设备文件资源管理器,lib在目录下:
那我怎样才能让 apk 使用正确的路径呢?
或者我错过了要添加的内容?
【问题讨论】:
标签: android android-ndk java-native-interface shared-libraries