I am trying to use a C library (apriltag) in my android app (4.4) using the NDK. I prebuilt the library using the android toolchain. After that, I followed this tutorial ( link ) to use apriltag in my C++ module.
My android.mk :
include $(CLEAR_VARS)
LOCAL_MODULE := apriltag_prebuilt_lib
LOCAL_SRC_FILES := $(LOCAL_PATH)/prebuilt/libapriltag.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gle_main
...
LOCAL_LDLIBS := -landroid -llog -lEGL -lGLESv2
LOCAL_SHARED_LIBRARIES += apriltag_prebuilt_lib
LOCAL_STATIC_LIBRARIES := cpufeatures android_native_app_glue ndk_helper
However, as soon as I reference it in another module, my app cannot even start. Android monitor tells me that process has died. If I comment the line LOCAL_SHARED_LIBRARIES I can start it but cannot use apriltag in my module...
Also, it works on Android 7. With this device I get the invalid DT_NEEDED entry "app/build/.../libapriltag.so" error for libgle_main.so (the c++ module that uses apriltag).
Any ideas to get it work on my Android 4.4 device ?
EDIT 1: I've added to my Activity :
static {
System.loadLibrary("apriltag");
System.loadLibrary("gle_main");
}
But now, I get this error :
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "sqrt" referenced by "/data/app/com.laas.lumus_app-1/lib/arm/libapriltag.so"
I guess it is related to the math library so I added to my gle_main
and my apriltag_prebuilt_lib
.
LOCAL_LDLIBS += -lm
Nothing changed.
Now, the app doesnt start on the 4.4 AND the 7.0 device.
Thank you in advance.
Because you are using a prebuilt shared library, libapriltag.so
. You have to let gradle add it to your apk also, and then you can use it into gle_main
. You have to add this line to your module/build.gradle script
android{
sourceSets.main{
jniLibs.srcDir 'path_to_libapriltag'
}
最后,我决定将所有源文件放入我的项目中,以使用Android Studio而不是使用外部工具链来完全构建它。
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.